8.6. Improved FacilitiesThe four clones all provide additional features that make simple text editing easier and more powerful.
8.6.1. Command-Line History and CompletionUsers 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. 8.6.2. Arbitrary Length Lines and Binary DataAll 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.
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. 8.6.3. Infinite UndoUNIX 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. 8.6.4. Incremental SearchingWhen 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.
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. Table 8.6. Incremental Searching
8.6.5. Left-Right ScrollingBy 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
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. 8.6.6. Visual ModeTypically, 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. 8.6.7. Mode IndicatorsAs 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. Table 8.8. Position and Mode Indicators
The GUI versions of elvis and vim change the cursor shape depending upon the current mode. Copyright © 2003 O'Reilly & Associates. All rights reserved. |
|