NEXT UP previous
 

Next: Edit Mode

Text Editing


If you are going to do more on your Linux machine than just execute pre-installed software packages, then at some point you WILL need to learn how to use one of the available text editors. There are a large number of editors to choose from with Linux and if you already know one of them you might as well continue to use it. However, if you don't know one of the editors yet, or if you might wish to migrate to other UNIX like environments in the future, then you should take the opportunity to master the standard UNIX screen editor called vi. In fact, the real vi editor is a proprietary product not directly available under Linux, although there are several (five or six at least) vi clone editors which are freely available for use under many systems, Linux included. If you make sure that you only learn the standard basic set of commands from these vi compatible editors, then you will be able to use any of them with equal ease.

Not only that, but you will be able to use vi on any flavor of UNIX, since EVERY UNIX like installation includes vi, o some equivallent.

From now on, I will use the word vi in a generic sense to mean any of the editors with vi compatibility (including elvis, vim, stevie, nvi, etc.)

The vi editor is a screen editor, which basically means that the contents of the screen is a window on the file being edited. In fact, vi makes all its changes to a copy of the file being edited, rather than the original. This means that if you make an error in editing you can always abort all the changes and return to the original file. It is only when you decide that things have gone properly, and issue the command to save the changes, that the original file is replaced by the updated version.

Actually vi is not an editor! vi is a (V)isual (I)nterpreter. The editor you will actually be using is called ed, vi just provides a convenient means of interacting with ed. The process of communication between vi and ed is completely transparent to you the user, you do not even need to know that ed exists, unless you feel the need to become a guru and lean the online man pages by heart, in which case you need to do a man ed as well as a man vi.

In order to get into vi you use a command like the following:

	$ vi filename

where filename is the pathname to the file you wish to edit. If the file does not already exist it will be created. The vi editor has three modes of operation called edit mode, insert mode and command mode (see Figure 1). As the diagram shows, when you run vi you start in edit mode. For the purposes of experimentation as we go along, it is recommended that you take a copy of one of the system text files in the /etc directory (/etc/passwd or /etc/printcap for instance) and use your copy to practice the editor commands as you meet them.


NEXT UP previous
Next: Edit Mode