Book HomeLearning the vi EditorSearch this book

9.8. Improvements for Editing

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

9.8.1. Command-Line History and Completion

nvi saves your ex command lines, and makes it possible to edit them for resubmission.

This facility is controlled with the cedit option.

When you type the first character of this string on the colon command line, nvi opens a new window on the command history that you can then edit. When you hit RETURN on any given line, nvi executes that line. ESC is a good choice for this option. (Use ^V ^[ to enter it.)

Because the RETURN key actually executes the command, be careful to use either the j or Figure keys to move down from one line to the next.

In addition to being able to edit your command line, you can also do filename expansion. This feature is controlled with the filec option.

When you type the first character of this string on the colon command line, nvi treats the blank delimited word in front of the cursor as if it had an * appended to it and does shell-style filename expansion. ESC is also a good choice for this option.[51] (Use ^V ^[ to enter it.) When this character is the same as for the cedit option, the command-line editing is performed only when it is entered as the first character on the colon command line.

[51]Although the nvi documentation indicates that TAB is another common choice, we could not get that to work. In practice, using ESC for both options works well.

It is easiest to set these options in your .nexrc file:

set cedit=^[
set filec=^[

9.8.2. Tag Stacks

Tag stacking is described in Section 8.5.3. nvi's tag stack is the simplest of the four clones. Table 9.2 and Table 9.3 show the commands it uses.

Table 9.2. nvi Tag Commands

Command Function
di[splay] t[ags]

Display the tag stack.

ta[g][!] tagstring

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

Ta[g][!] tagstring

Just like :tag, except that the file is edited in a new window.

tagp[op][!] tagloc

Pop to the given tag, or to the most recently used tag if no tagloc is supplied. The location may be either a filename of the tag of interest or a number indicating a position in the stack.

tagt[op][!]

Pop to the oldest tag in the stack, clearing the stack in the process.

Table 9.3. nvi 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.

You can set the tags option to a list of file names where nvi should look for a tag. This provides a simplistic search path mechanism. The default value is "tags /var/db/libc.tags /sys/kern/tags", which on a 4.4BSD system looks in the current directory, and then in the files for the C library and the operating system source code.

The taglength option controls how many characters in a tagstring are significant. The default value of zero means to use all the characters.

nvi behaves like vi; it uses the "word" under the cursor starting at the current cursor position. If your cursor is on the i in main, nvi will search for the identifier in, not main.

nvi relies on the traditional tags file format. Unfortunately, this format is very limited. In particular, it has no concept of programming language scope, which allows the same identifier to be used in different contexts to mean different things. The problem is exacerbated by C++, which explicitly allows function name overloading, i.e., the use of the same name for different functions.

nvi gets around the tags file limitations by using a different mechanism entirely: the cscope program. cscope is a proprietary but relatively inexpensive program available from the Bell Labs Software Toolchest. It reads C source files and builds a database describing the program. nvi provides commands that query the database and allow you to process the results. Because cscope is not universally available, we do not cover its use here. Details of the nvi commands are provided in the nvi documentation.

The extended tags file format produced by Exuberant ctags does not produce any errors with nvi 1.79; however, nvi does not take advantage of this format either.

9.8.3. Infinite Undo

In vi, the dot (.) command generally acts as the "do again" command; it repeats the last editing action you performed, be it a deletion, insertion, or replacement.

nvi generalizes the dot command into a full "redo" command, applying it even if the last command was u for "undo."

Thus, to begin a series of "undo" commands, first type a u. Then, for each . (dot) that you type, nvi will continue to undo changes, moving the file progressively closer to its original state.

Eventually, you will reach the initial state of your file. At that point, typing . will just ring the bell (or flash the screen). You can now begin redoing by typing u to "undo the undos" and then using . to reapply successive changes.

nvi does not allow you to provide a count to either the u or . command.

9.8.4. Arbitrary Length Lines and Binary Data

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

nvi automatically handles binary data. No special command-line options or ex options are required. You use ^X followed by one or two hexadecimal digits to enter any 8-bit character into your file.

9.8.5. Incremental Searching

As mentioned in Section 8.6.4, you enable incremental searching in nvi using :set searchincr.

The cursor moves through the file as you type, always being placed on the first character of the text that matches.

9.8.6. Left-Right Scrolling

As mentioned in Section 8.6.5, you enable left-right scrolling in nvi using :set leftright. The value of sidescroll controls the number of characters by which nvi shifts the screen when scrolling left to right.



Library Navigation Links

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