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

  • Vi is universally available on Unix systems. It has been around so long in a stable form that it is essentially bug free. Many clones have been written for other kinds of computers.
  • Vi has many powerful commands that utilize just the alphanumeric keys -- it does not require special function keys.
  • Vi is a small program that does not require a lot of system memory or CPU time. It works very fast, even on large files.
  • While vi is not programmable, it has a simple way to let other Unix programs, such as the sort utility, work on selected portions of your file. This adds the functionality of all those programs to the editor.
  • Vi is completely terminal device independent. It will work with any kind of terminal.

    A system file describes the capabilities and control sequences of each kind of terminal for vi. All the program needs to know is what type of terminal you have. When you log in, if pangea cannot figure out what kind of terminal you have, it will prompt you to specify a terminal type. The most common type is the vt100, which most modern terminals and PC communications software emulate.

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.

Comments or Questions?