Before vi was developed, the standard UNIX system editor was ed (still available on Mac OS X systems), a line-oriented editor that made it difficult to see the context of your editing. Next came ex, a superset of ed. The most notable advantage that ex has over ed is a display-editing facility that allows you to work with a full screen of text instead of just a line. While using ex, you can bring up the display-editing facility by giving a vi (Visual mode) command. People used this display-editing facility so extensively that the developers of ex made it possible to start the editor with the display-editing facility already running, without having to start ex and then give a vi command. Appropriately they named the program vi. You can call the Visual mode from ex, and you can go back to ex while you are using vi. Start by running ex; give a vi command to switch to Visual mode, and give a Q command while in Visual mode to use ex. Give a quit command to exit from ex.
There are a number of versions, or clones, of vi. The most popular vi clones are elvis (elvis.the-little-red-haired-girl.org), nvi (an implementation of the original vi editor, www.bostic.com/vi), vile (dickey.his.com/vile/vile.html), and vim (www.vim.org). Each clone offers additional features beyond those provided with the original vi. The examples in this book are based on vim.
If you use one of the clones other than vim, or vi itself, you may notice slight differences from the examples presented in this chapter. The vim editor is compatible with almost all vi commands and runs on many platforms, including Windows, Macintosh, OS/2, UNIX, and Linux. Refer to the vim home page (www.vim.org) for more information and a very useful Tips section.
What vim is not
The vim editor is not a text formatting program. It does not justify margins or provide the output formatting features of a sophisticated word processing system such as AppleWorks. Rather, vim is a sophisticated text editor meant to be used to write code (C, HTML, Java, and so on), short notes, and input to a text formatting system, such as groff or TRoff. You can use fmt (page 736) to do minimal formatting on a text file that you create with vim.
Reading this chapter
Because vim is so large and powerful, this chapter describes only some of its features. Nonetheless, if vim is completely new to you, you may find even this limited set of commands overwhelming. The vim editor provides a variety of ways to accomplish any specified editing task. A useful strategy for learning vim is to begin by learning a subset of commands to accomplish basic editing tasks. Then, as you become more comfortable with the editor, you can learn other commands that enable you to do things more quickly and efficiently. The following tutorial section introduces a basic but useful set of vim commands and features that create and edit a file.