home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book HomeLearning the vi EditorSearch this book

8.6. Improved Facilities

The four clones all provide additional features that make simple text editing easier and more powerful.

Editing the ex command line
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.

No line length limit
The ability to edit lines of essentially arbitrary length. Also, the ability to edit files containing any 8-bit character.

Infinite undo
The ability to successively undo all of the changes you've made to a file.

Incremental searching
The ability to search for text while you are typing the search pattern.

Left/right scrolling
The ability to let long lines trail off the edge of screen instead of wrapping.

Visual mode
The ability to select arbitrary contiguous chunks of texts upon which some operation will be done.

Mode indicators
A visible indication of insert mode versus command mode, as well as indicators of the current line and column.

8.6.2. Arbitrary Length Lines and Binary Data

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.

nvi
Automatically handles binary data. No special command-line or ex options are required.

elvis
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.)

vim
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.

vile
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.

8.6.5. Left-Right Scrolling

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.

Table 8.7. Sideways Scrolling

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 sidescroll set to zero, each scroll puts the cursor in the middle of the screen. Otherwise the screen scrolls by the desired number of characters.

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 < and >. With sideways set to zero, each scroll moves the screen by Figure . Otherwise the screen scrolls by the desired number of characters.

    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.



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.