The four clones all provide additional features that make simple text editing easier and more powerful.
Users of the csh, tcsh, ksh, and bash shells have known for years that being able to recall previous commands, edit them slightly, and resubmit them makes them more productive.
This is no less true for editor users than it is for shell users; unfortunately, UNIX vi does not have any facility to save and recall ex commands.
This lack is remedied in each of the clones. Although each one provides a different way of saving and recalling the command history, each one's mechanism is usable and useful.
In addition to a command history, all of the editors can do some kind of completion. This is where you type the beginning of, for example, a filename. You then type a special character (such as tab), and the editor completes the filename for you. All of the editors can do filename completion, some of them can complete other things as well. Details are provided in each editor's chapter.
All four clones can handle lines of any length.[44] Historic versions of vi often had limits of around 1,000 characters per line; longer lines would be truncated.
[44]Well, up to the maximum value of a C long, 2,147,483,647.
All four are also 8-bit clean, meaning that they can edit files containing any 8-bit character. It is even possible to edit binary and/or executable files, if necessary. This can be really useful, at times. You may or may not have to tell each editor that a file is binary.
Finally, there is one tricky detail. Traditional vi always writes the file with a final newline appended. When editing a binary file, this might add one character to the file and cause problems. nvi and vim are compatible with vi by default, and add that newline. In vim you can set the binary option, so this doesn't happen. elvis and vile never append the extra newline.
UNIX vi allows you to undo only your last change, or to restore the current line to the state it was in before you started making any changes. All of the clones provide "infinite undo," the ability to keep undoing your changes, all the way back to the state the file was in before you started any editing.
When incremental searching is used, the editor moves the cursor through the file, matching text as you type the search pattern. When you finally type RETURN, the search is finished.[45] If you've never seen it before, it is rather disconcerting at first, but after a while you get used to it.
[45]emacs has always had incremental searching.
elvis does not support incremental searching. nvi and vim enable incremental searching with an option, and vile uses two special vi mode commands. vile can be compiled with incremental searching disabled, but it is enabled by default. Table 8.6 shows the options each editor provides.
By default, vi and most of the clones wrap long lines around the screen. Thus, a single logical line of the file may occupy multiple physical lines on your screen.
There are times when it might be preferable if a long line simply disappeared off the right-hand edge of the screen, instead of wrapping. Moving onto that line and then moving to the right would "scroll" the screen sideways. This feature is available in all of the clones. Typically, a numeric option controls how much to scroll the screen, and a Boolean option controls whether lines wrap or disappear off the edge of the screen. vile also has command keys to perform sideways scrolling of the entire screen. Table 8.7 shows how to use horizontal scrolling with each editor.
vile has two additional commands, ^X ^R and ^X ^L. These two commands scroll the screen right and left, respectively, leaving the cursor in its current location on the line. You cannot scroll so far that the cursor position would go off the screen.
Typically, operations in vi apply to units of text such lines, words, or characters, or to sections of text from the current cursor position to a position specified by a search command. For example, d/^} deletes up to the next line that starts with a right brace. elvis, vim, and vile all provide a mechanism to explicitly select a region of text to which an operation will apply. In particular, it is possible to select a rectangular block of text and apply an operation to all the text within the rectangle! See each editor's respective chapter for the details.
As you know by now, vi has two modes, command mode and insert mode. Usually, you can't tell by looking at the screen which mode you're in. Furthermore, often it's useful to know where in the file you are, without having to use the ^G or ex := commands.
Two options address these issues, showmode and ruler. All four clones agree on the option names and meanings, and even Solaris vi has the showmode option.
Table 8.8 lists the special features in each editor.
Editor | With ruler, displays | With showmode, displays |
---|---|---|
nvi | row and column | |
elvis | row and column | |
vim | row and column | |
vile | row, column, and percent of file | |
vi | N/A | separate mode indicators for open, input, insert, append, change, replace, replace one character, and substitute modes |
The GUI versions of elvis and vim change the cursor shape depending upon the current mode.
Copyright © 2003 O'Reilly & Associates. All rights reserved.