Class 7 of 37 • VI Editor Mastery \t\t\t\t

Overview of VI Editor in Linux Programming - Modal Text Editing Philosophy

 The VI editor (short for Visual Editor) is a full-screen, display-oriented text editor available on virtually all Unix, Linux, and POSIX operating systems. Originally developed by Bill Joy in 1976 for BSD Unix, it remains an indispensable tool for Linux system administrators, DevOps engineers, and C/Python programmers worldwide.

 Once you learn VI's touch-typing workflow, you will find it is one of the fastest, most lightweight, and powerful editors in existence. Unlike GUI code editors, VI has no graphical buttons or menus; instead, it uses efficient combinations of mnemonic keystrokes to accomplish complex editing commands without ever lifting your hands off the keyboard.

VI Editor Modes Architecture

Figure 1: State transitions between Command, Insert, and Last-Line (Ex) Modes in VI editor.

The Modal Editing Philosophy

Most text editors (such as Notepad, Microsoft Word, or Nano) are modeless: whenever you press an alphanumeric key, that character is immediately inserted into the document. To move the cursor or delete text, you must use arrows, the mouse, or hold down awkward modifier keys like Ctrl or Alt.

VI solves this ergonomic bottleneck through Modal Editing. The keyboard is split into distinct operational modes:

  1. Command Mode (Default): When you open a file in VI, you enter Command Mode. Keystrokes do not type text; instead, single letters act as commands. For example, pressing dd deletes a line, yy copies a line, and h, j, k, l move the cursor.
  2. Insert Mode: Triggered by pressing i, a, or o from Command Mode. In this mode, every keystroke inputs text into the file just like a regular text editor. Pressing Esc returns you safely back to Command Mode.
  3. Last-Line (Ex) Mode: Triggered by pressing the colon (:) key in Command Mode. The cursor jumps to the bottom status line of the terminal, allowing you to run powerful system commands like saving (:w), quitting (:q), and search & replace (:%s/old/new/g).

Starting the VI Editor

To launch VI from your Linux terminal prompt, type vi (or vim) followed by the target filename:

$ vi filename.txt

If filename.txt already exists on disk, VI loads a copy of its content into a temporary memory buffer. If it does not exist, VI opens a clean new buffer and will create the file on disk when you issue the save command.

Screen Display in VI

When VI launches with a new file, the terminal displays empty lines prefixed by tilde characters (~). The tildes indicate that those lines are empty and do not yet exist in the file buffer. The bottom line displays the filename, current line count, and character statistics.

VI vs Nano vs Emacs: Comparison Table

Feature

VI / VIM

GNU Nano

GNU Emacs

Architecture

Modal (Command, Insert, Ex modes)

Modeless (Direct typing)

Modeless + Lisp extensible environment

System Availability

100% Guaranteed (POSIX requirement on all Linux/Unix)

Common on desktop Linux, missing on minimal servers/containers

Optional large package; rarely pre-installed

Memory Footprint

Extremely lightweight (~2 MB RAM)

Lightweight (~3 MB RAM)

Heavy (~50+ MB RAM)

Ideal Use Case

Remote server administration, high-speed coding, configuration edits

Quick casual configuration changes for beginners

Full Lisp-programmable development IDE

Lab Practice: First-Time VI File Creation and Safe Exit Drill

Practice this fundamental workflow in your terminal:

  1. Open terminal and type: vi welcome.txt
  2. Verify you are in Command Mode. Press i to enter Insert Mode. Look for -- INSERT -- at the bottom.
  3. Type: Welcome to Linux Programming at Veewom.com!
  4. Press Esc to leave Insert Mode.
  5. Type :wq and hit Enter to write changes and quit to the Linux prompt.
  6. Verify file was created: ls -l welcome.txt && cat welcome.txt.

Frequently Asked Questions (FAQs)

VI is a standard screen-oriented text editor available by default on every Unix and Linux distribution. It enables fast text manipulation using keyboard commands organized into distinct operational modes.
VI is mandated by POSIX standards and is installed on every cloud server, rescue environment, Docker container, and embedded Linux system. It requires no graphical interface and operates smoothly even over slow, high-latency SSH connections.
The tilde symbol indicates lines on the terminal screen that do not exist in the actual file buffer (i.e. empty buffer space past the end of the file).
Press the Esc key twice to ensure you are in Command Mode, then type :q! and press Enter. This immediately exits vi without saving any changes.

Next Step in Your Linux Learning Path:

Learn how Bill Joy crafted VI on the Lear Siegler ADM-3A terminal in Class 8: History of VI Editor.

Continue to Class 8: History of VI → Previous: ← Bash Shell | Full Syllabus

Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Stumbleupon Share on Tumblr Share on Reddit Share on Diggit

You may also like this!