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


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



Library Navigation Links

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