Characteristics, advantages, and disadvantages of vi



Last revision August 2, 2004

Table of Contents:
  1. Editor choices on Unix
  2. Characteristics, advantages, and disadvantages of vi
  3. Basic text editing operations in vi
  4. Regular expressions
  5. File searching with grep
  6. More about regular expressions
  7. Intermediate text editing with vi
  8. Vi Quick Reference

Vi is a screen editor. It treats your computer screen as a window into the file. You move the window around to view different parts of the file. You move the cursor to the location on the screen where you want to make a change; or optionally, you specify some kind of global change. Vi updates your screen to reflect changes that you make in the file. Actually, it works on a copy of the file in memory, and only updates the file on disk when you tell it to, such as when you end the editing session.

In every editor, the input device (keyboard) has two functions, to insert text into the file and give commands to instruct the editor what to do.

Every editor has to have some means of keeping these functions separated. Most editors do this by either using special function keys (or a mouse) to give or start commands, or by requiring that the cursor be located on a special command line or area of the screen to give commands. In these types of editors, the keyboard is normally inserting or replacing text; keystrokes are not normally interpreted as commands to the editor.

Vi takes a different approach to separating commands from text: modes. Vi has two modes: command and insert.

When in command mode, which is where you start out, everything you type, every key you press, is interpreted as a command to vi. You have to give special commands to switch to insert mode.

When in insert mode, typing causes text to be inserted into the file (actually into the copy in memory, called the buffer). You have to press a special key (ESC) to go back to command mode.

Main advantages of vi

The chief disadvantage of vi is that it is touchy. That is, every single key you touch on the keyboard seems to do something, often something mysterious. There is a rich set of single character commands to learn.

Like most things in Unix, vi is not column oriented. It does not have commands for affecting specific columns of each line (say columns 5-15). Rather, it is field or pattern oriented. Commands can be limited to a specified pattern of characters.