start page | rating of books | rating of authors | reviews | copyrights

Book HomeLearning the vi EditorSearch this book

10.8. Improved Editing Facilities

This section describes the features of elvis that make simple text editing easier and more powerful.

10.8.1. Command-Line History and Completion

Everything you type on the ex command line is saved in a buffer named Elvis ex history. This is accessible like any other elvis buffer, but is not directly useful when just viewed in a window.

In order to access the history, you use the arrow keys on your terminal to display previous commands and to edit them. Use Figure and Figure to page through the list, and Figure and Figure to move around on a command line. You can insert characters by typing and erase them by backspacing over them. Much as when editing in a regular vi buffer, the backspace does remove the characters, but the line is not updated as you type, so be careful!

When entering text into the Elvis ex history buffer (i.e., on the colon command line), the TAB key can be used for filename expansion. The preceding word is assumed to be a partial filename, and elvis searches for all matching files. If there are multiple matches, it fills in as many characters of the name as possible, and then beeps; or, if no additional characters are implied by the matching filenames, elvis lists all matching names and redisplays the command line. If there is a single match, elvis completes the name and appends a tab character. If there are no matches, elvis simply inserts a tab character.

To get a real tab character, precede it with a ^V. You can also disable filename completion entirely by setting the Elvis ex history buffer's inputtab option to tab, via the following command:

:(Elvis ex history)set inputtab=tab

10.8.2. Tag Stacks

Tag stacking is described in Section 8.5.3. In elvis, tag stacking is very straightforward, as shown in Table 10.5 and Table 10.6.

Table 10.5. elvis Tag Commands

Command Function
ta[g][!] [tagstring]

Edit the file containing tagstring as defined in the tags file. The ! forces elvis to switch to the new file if the current buffer has been modified but not saved.

stac[k]

Display the current tag stack.

po[p][!]

Pop a cursor position off the stack, restoring the cursor to its previous position.

Table 10.6. elvis Command Mode Tag Commands

Command Function
^]

Look up the location of the identifier under the cursor in the tags file, and move to that location. The current location is automatically pushed onto the tag stack.

^T

Return to the previous location in the tag stack, i.e., pop off one element.

Unlike traditional vi, when you type ^], elvis looks up the entire word containing the cursor, not just the part of the word from the cursor location forward.

In HTML mode (discussed in Section 10.10.1), the commands all work the same except that :tag expects to be given a URL instead of a tag name. URLs don't depend on having a tags file, so the tags file is ignored when in HTML mode. elvis 2.0 doesn't support any network protocols,[54] so its URLs can only consist of a file name and/or an HTML #label.

[54]This is no longer true in elvis 2.1; see Section 10.11 for details.

Several :set options affect how elvis works with tags, as described in Table 10.7.

Table 10.7. elvis Options for Tag Management

Option Function
taglength, tl

Control the number of significant characters in a tag that is to be looked up. The default value of zero indicates that all characters are significant.

tags, tagpath

The value is a list of directory and/or filenames in which to look for tags files. elvis looks for a file named tags in any entry that is a directory. Entries in the list are colon-separated (or semicolon on DOS/Windows), in order to allow spaces in directory names. The default value is just "tags", which looks for a file named tags in the current directory. This can be overridden by setting the TAGPATH environment variable.

tagstack

When set to true, elvis stacks each location on the tag stack. Use :set notagstack to disable tag stacking.

Version 2.1 of elvis (in beta test as of this writing) supports the extended tags file format described earlier. elvis comes with its own version of ctags. The version in elvis 2.1 generates the enhanced format described earlier. Here is an example of the special !_TAG_ lines it produces:

!_TAG_FILE_FORMAT       2       /supported features/
!_TAG_FILE_SORTED       1       /0=unsorted, 1=sorted/
!_TAG_PROGRAM_AUTHOR    Steve Kirkendall        /[email protected]/
!_TAG_PROGRAM_NAME      Elvis Ctags     //
!_TAG_PROGRAM_URL       ftp://ftp.cs.pdx.edu/pub/elvis/README.html  //
!_TAG_PROGRAM_VERSION   2.1     //

Finally, in elvis, each window has its own tag stack.

10.8.3. Infinite Undo

With elvis, before being able to undo and redo multiple levels of changes, you must first set the undolevels option to the number of levels of "undo" that elvis should allow. A negative value disallows any undoing (which is not terribly useful). The elvis documentation warns that each level of undo uses around 6K bytes of the session file (the file that describes your editing session), and thus can eat up disk space rather quickly. It recommends not setting undolevels any higher than 100 and "probably much lower."

Once you've set undolevels to a non-zero value, you enter text as normal. Then each successive u command undoes one change. To redo (undo the undo), you use the (rather mnemonic) CTRL-R command.

In elvis, the default value of undolevels is zero, which causes elvis to mimic UNIX vi. The option applies per buffer being edited; see Section 10.4.2 for a description of how to set it for every file that you edit.

Once undolevels has been set, a count to either the u or ^R commands undoes or redoes the given number of changes.

10.8.4. Arbitrary Length Lines and Binary Data

elvis can edit files with arbitrary length lines, and with an arbitrary number of lines.

Under UNIX, elvis 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. This avoids newline translation issues. You can enter eight-bit text by typing ^X followed by two hexadecimal digits. Using the hex display mode is an excellent way to edit binary files. (The elvis.brf file and the hex display mode are described in Section 10.10.)

10.8.5. Left-Right Scrolling

As mentioned in Section 8.6.4, you enable left-right scrolling in elvis using :set nowrap. The value of sidescroll controls the number of characters by which elvis shifts the screen when scrolling left to right. The ^W S command toggles the value of this option.

10.8.6. Visual Mode

elvis allows you to select regions one character at a time, one line at a time, or rectangularly, using the commands shown in Table 10.8.

Table 10.8. elvis Block Mode Command Characters

Command Function
v

Start region selection, character at a time mode.

V

Start region selection, line at a time mode.

^V

Start region selection, rectangular mode.

elvis highlights (using reverse video) the text as you are selecting. To make your selection, simply use the normal motion keys. The screen below shows a rectangular region:


The 6th edition of <citetitle>Learning the vi Editor</citetitle>
brings the book into the late 1990&rsquo;s.


In particular, besides the &ldquo;original&rdquo; version of


<command>vi</command> that comes as a standard part of every UNIX


 
system, there are now a number of freely available &ldquo;clones&rdquo;
or work-alike editors.

elvis only permits a few operations on selected areas of text. Some operations work only on whole lines, even if you've selected a region that does not contain whole lines (see Table 10.9).

Table 10.9. elvis Block Mode Operations

Command Operation
c, d, y

Change, delete, or yank text. Only d works exactly on rectangles.

<, >, !

Shift text left or right, filter text. These operate on the whole lines containing the marked region.

After using the d command to delete the region, the screen now looks like this:

The 6th edition of <citetitle>Learning the vi Editor</citetitle>
brings the 90&rsquo;s.
In particulo;original&rdquo; version of
<command>vi as a standard part of every
system, there are n available &ldquo;clones&rdquo;
or work-alike editors.


Library Navigation Links

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