The four clones all provide additional features that make simple text editing easier and more powerful.
The ability to edit ex mode commands as you type them, possibly including a saved history of ex commands. Also, the ability to complete filenames and possibly other things, such as commands and options.
The ability to edit lines of essentially arbitrary length. Also, the ability to edit files containing any 8-bit character.
The ability to successively undo all of the changes you've made to a file.
The ability to search for text while you are typing the search pattern.
The ability to let long lines trail off the edge of screen instead of wrapping.
The ability to select arbitrary contiguous chunks of texts upon which some operation will be done.
A visible indication of insert mode versus command mode, as well as indicators of the current line and column.
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.[7] Historic versions of vi often had limits of around 1,000 characters per line; longer lines would be truncated.
[7] 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.
Automatically handles binary data. No special command-line or ex options are required.
Under UNIX, does not treat a binary file differently from any
other file. On other systems, it uses the elvis.brf
file to set the binary
option, to avoid
newline translation issues.
(The elvis.brf file and hex
display modes are described in
Section 10.10, "Interesting Features" in Chapter 10.)
Does not have a limit on the length of a line.
When binary
is not set, vim is
like nvi, and automatically handles binary data.
However, when
editing a binary file, you should either use the
-b command-line option
or :set binary
.
These set several other vim options that make it
easier to edit binary files.
Automatically handles binary data. No special command-line or ex options are required.
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.[8] If you've never seen it before, it is rather disconcerting at first, but after a while you get used to it.
[8] 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.
Editor | Option | Command | Action |
---|---|---|---|
nvi | searchincr | The cursor moves through the file as you type, always being placed on the first character of the text that matches. | |
vim | incsearch | The cursor moves through the file as you type. vim highlights the text that matches what you've typed so far. | |
vile | ^X S , ^X R | The cursor moves through the
file as you type, always being placed on the first character of
the text that matches. |
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.
Editor | Scroll Amount | Option | Action |
---|---|---|---|
nvi | sidescroll = 16 | leftright | Off by default. When set, long lines simply go off the edge of the screen. The screen scrolls left or right by 16 characters at a time. |
elvis | sidescroll = 8 | wrap | Off by default. When set, long lines simply go off the edge of the screen. The screen scrolls left or right by 8 characters at a time. |
vim | sidescroll = 0 | wrap | Off by default.
When set, long lines simply go off the edge of the screen.
With |
vile | sideways = 0 | linewrap | Off by default.
When set, long lines wrap. Thus, the default is to have long
lines go off the edge of the screen.
Long lines are marked at the left and right edges with
|
horizscroll | On by default. When set, moving the cursor along a long line off-screen shifts the whole screen. When not set, only the current line shifts; this may be desirable on slower displays. |
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.