A Brief Historical Perspective

Before diving into all the ins and outs of vi, it will help you to understand vi’s worldview of your environment. In particular, this will help you make sense of many of vi’s otherwise more obscure error messages, and also appreciate how the vi clones have evolved beyond the original vi.

vi dates back to a time when computer users worked on terminals connected via serial lines to central mini-computers. Hundreds of different kinds of terminals existed and were in use worldwide. Each one did the same kind of actions (clear the screen, move the cursor, etc.), but the commands needed to make them do these actions were different. In addition, the Unix system let you choose the characters to use for backspace, generating an interrupt signal, and other commands useful on serial terminals, such as suspending and resuming output. These facilities were (and still are) managed with the stty command.

The original UCB version of vi abstracted out the terminal control information from the code (which was hard to change) into a text-file database of terminal capabilities (which was easy to change), managed by the termcap library. In the early 1980s, System V introduced a binary terminal information database and terminfo library. The two libraries were largely functionally equivalent. In order to tell vi which terminal you had, you had to set the TERM environment variable. This was typically done in a shell startup file, such as .profile or .login.

Today, everyone uses terminal emulators in a graphic environment (such as xterm). The system almost always takes care of setting TERM for you. (You can use vi from a PC non-GUI console too, of course. This is very useful when doing system recovery work in single-user mode. There aren’t too many people left who would want to work this way on a regular basis, though.) For day-to-day use, it is likely that you will want to use a GUI version of vi, such as Vim or one of the other clones. On a Microsoft Windows or Mac OS X system, this will probably be the default. However, when you run vi (or some other screen editor of the same vintage) inside a terminal emulator, it still uses TERM and termcap or terminfo and pays attention to the stty settings. And using it inside a terminal emulator is just as easy a way to learn vi as any other.

Another important fact to understand about vi is that it was developed at a time when Unix systems were considerably less stable than they are today. The vi user of yesteryear had to be prepared for the system to crash at arbitrary times, and so vi included support for recovering files that were in the middle of being edited when the system crashed.[8] So, as you learn vi and see the descriptions of various problems that might occur, bear these historical developments in mind.



[8] Thankfully, this kind of thing is much less common, although systems can still crash due to external circumstances, such as a power outage.

Get Learning the vi and Vim Editors, 7th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.