Chapter 5. Editing Files with Vi

Table of Contents
Modal editing
Starting Vi
Stopping Vi
Common tasks
Gaining proficiency
Endorsement

Modal editing

The Vi editor is the quintessential unix text editor. It is relatively small in terms of program size, and is generally the one editor guaranteed present on any unix system. Anyone wishing to use a unix system seriously should obtain at least minimal skills with Vi.

The most difficult aspect for beginners to understand about Vi is that it is a modal editor. What that means is that there is a distinct mode the editor must be in for typing text, and a different mode for editing, pasting, and cursor movement. The typing mode is called insert mode, and the other mode is called command mode.

Other editors have modes, but not in the obvious way that Vi does. If Alt-F brings down a File menu in your favorite editor, you have implicitly switched from insert mode to command mode by pressing the Alt key. The same is true when you click a menu selection with the mouse. Historically, Alt keys and Ctrl keys have not worked well in all unix environments, or have worked differently from computer to computer. Because of this, Vi does not make use of them the same way that other editors do.

With Vi, changing modes requires an explicit act, and somewhat unintuitively the editor begins in command mode. In command mode, the letters of the alphabet (that you would normally use to type data into a document) perform editing functions instead. Some letters move the cursor around (you can quickly move by characters, words, sentences, lines and paragraphs). Other letters delete text (you can easily delete characters, words, sentences, and so on). Since every computer has alphabet keys that work the same way, the Vi editor is guaranteed to work well everywhere.