Book HomeLearning the vi EditorSearch this book

12.8. Improved Editing Facilities

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

12.8.1. Command-Line History and Completion

vile stores all your ex commands in a buffer named [History]. This feature is controlled with the history option, which is true by default. Turning it off disables the history feature and removes the [History] buffer. The command show-history will split the screen and display the [History] buffer in a new window.

Starting with vile 7.4, the colon command line is really a minibuffer. You can use it to recall lines from the [History] buffer and edit them.

You use the Figure and Figure keys to scroll backward and forward in the history, and Figure and Figure to move around within the line. Your current delete character (usually BACKSPACE) can be used to delete characters. Any other characters you type will be inserted at the current cursor postion.

You can toggle the minibuffer into vi mode by typing the mini-edit character (by default, ^G). When you do this, vile will highlight the minibuffer using the mechanism specified by the mini-hilite option. The default is reverse, for reverse video. In vi mode, you can use vi style commands for positioning. In Version 8.0, you can also use the i, I, a, and A vi commands.

An interesting feature is that vile will use the history to show you previous data that corresponds to the command you're entering. For instance, after typing :set followed by a space, vile will prompt you with Global value:. At that point, you can use Figure to see previous global variables that you've set, should you wish to change one of them.

The ex command line provides completion of various sorts. As you type the name of a command, you can hit the TAB key at any point. vile will fill out the rest of the command name as much as possible. If you type a TAB a second time, vile will create a new window showing you all the possible completions.

Completion applies to built-in and user-defined vile commands, tags, filenames, modes (described later in this chapter), variables, and to the terminal characters (the character settings such as backspace, suspend, and so on, derived from your stty settings).

As a side point, this leads to an interesting phenomenon. In vi-style editors, commands may have long names, but they tend to be unique in the first few characters, since abbreviations are accepted. In emacs-style editors, command names often are not unique in the first several characters, but command completion still allows you to get away with less typing.

12.8.2. Tag Stacks

Tag stacking is described in Section 8.5.3. In vile, tag stacking is available and straightforward. It is somewhat different than the other clones, most notably in the vi mode commands that are used for tag searching and popping the tag stack. Table 12.2 shows the vile tag commands.

Table 12.2. vile Tag Commands

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

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

pop[!]

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

next-tag

Continues searching through the tags file for more matches.

show-tagstack

Creates a new window that displays the tag stack. The display changes as tags are pushed onto or popped off of the stack.

The vi mode commands are described in Table 12.3.

Table 12.3. vile 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    ^X ^]

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

^A ^]

Same as the :next-tag command.

As in the other editors, options control how vile manages the tag related commands, as shown in Table 12.4.

Table 12.4. vile Options for Tag Management

Option Function
taglength

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

tagignorecase

Makes tag searches ignore case. By default this option is false.

tagrelative

When using a tags file in another directory, filenames in that tags file are considered to be relative to the directory where the tags file is.

tags

Can be set to a whitespace separated list of tags files to use for looking up tags. vile loads all tags files into separate buffers that are hidden by default, but that can be edited if you wish. You can place environment variables and shell wildcards into tags.

tagword

Uses the whole word under the cursor for the tag lookup, not just the sub-word starting at the current cursor position. This option is disabled by default, which keeps vile compatible with vi.

12.8.3. Infinite Undo

vile is similar in principle but different in practice from the other editors. Like elvis and vim, there is an undo limit you can set, but like nvi, the . command will do the next undo or redo, as appropriate it. Separate vi mode commands implement successive undo and redo.

vile uses the undolimit option to control how many changes it will store. The default is 10, meaning that you can undo up to the 10 most recent changes. Setting it to zero allows true "infinite undo," but this may consume a lot of memory.

To start an undo, first use either the u or ^X u commands. Then each successive . command will do another undo. Like vi, two u commands just toggle the state of the change; however, each ^X u command does another undo.

The ^X r command does a redo. Typing . after the first ^X r will do successive redos. You can provide a count to the ^X u and ^X r commands, in which case vile will perform the requested number of undos or redos.

12.8.4. Arbitrary Length Lines and Binary Data

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

vile automatically handles binary data. No special command lines or options are required. To enter 8-bit text, type ^V followed by an x and two hexadecimal digits, or a 0 and three octal digits, or three decimal digits.

12.8.5. Incremental Searching

As mentioned in Section 8.6.4, you perform incremental searching in vile using the ^X S and ^X R commands. It is not necessary to set an option to enable incremental searching.

The cursor moves through the file as you type, always being placed on the first character of the text that matches. ^X S incrementally searches forward through the file, while ^X R incrementally searches backwards.

You may wish to add these commands (described below) to your .vilerc file to make the more familiar / and ? search commands work incrementally:

bind-key incremental-search /
bind-key reverse-incremental-search ?

Also of interest is the "visual match" facility, which will highlight all occurrences of the matched expression. For a .vilerc file:

set visual-matches reverse

This command directs vile to use reverse video for visual matching. Since the highlighting can sometimes be visually distracting, the = command will turn off any current highlighting until you enter a new search pattern.

12.8.6. Left-Right Scrolling

As mentioned in Section 8.6.5 in Chapter 8, you enable left-right scrolling in vile using :set nolinewrap. Unlike the other editors, left-right scrolling is the default. Long lines are marked at the left and right edges with < and >. The value of sideways controls the number of characters by which vile shifts the screen when scrolling left to right. With sideways set to zero, each scroll moves the screen by one third. Otherwise the screen scrolls by the desired number of characters.

12.8.7. Visual Mode

vile is different from elvis and vim in the way you highlight the text you want to operate on. It uses the "quoted motion" command, q.

You enter q at the beginning of the region, any other vi motions to get to the opposite end of the region, and then another q to end the quoted motion. vile highlights the marked text.

Arguments to the q command determine what kind of highlighting it will do. 1q (same as q) does an exact highlighting, 2q does line-at-a-time highlighting, and 3q does rectangular highlighting.

Typically, you use a quoted motion in conjunction with an operator, such as d or y. Thus, d3qjjwq deletes the rectangle indicated by the motions. When used without an operator, the region is left highlighted. It can be referred to later using ^S. Thus, d ^S will delete the highlighted region.

In addition, rectangular regions can be indicated through the use of marks.[61] As you know, a mark can be used to refer to either a specific character (when referred to with `) or a specific line (when referred to with '). In addition, referring to the mark (say a mark set with mb) with `b instead of 'b can change the nature of the operation being done—d'b will delete a set of lines, and d`b will delete two partial lines and the lines in between. Using the ` form of mark reference gives a more "exact" region than the ' form of mark reference.

[61]Thanks to Paul Fox for this explanation.

vile adds a third form of mark reference. The \ command can be used as another way of referring to a mark. By itself, it behaves just like ` and moves the cursor to the character at which the mark was set. When combined with an operator, however, the behavior is quite different. The mark reference becomes "rectangular," such that the action d\b will delete the rectangle of characters whose corners are marked by the cursor and the character which holds mark b.

Keystrokes
ma  

Figure 12.8.7
Results

Set mark a at the b in book.

 

Keystrokes
3jfr  

Figure 12.8.7
Results

Move the cursor to the r in number to mark the opposite corner.

 

Keystrokes
^A ~\a  

Figure 12.8.7
Results

Toggle the case of rectangle bounded with mark a.

 

The commands which define arbitrary regions and operate upon them are summarized in Table 12.5.

Table 12.5. vile Block Mode Operations

Command Operation
q

Start and end a quoted motion.

^A r

Open up a rectangle.

>

Shift text to the right. Same as ^A r when the region is rectangular.

<

Shift text to the left. Same as d when the region is rectangular.

y

Yank the whole region. vile remembers that it was rectangular.

c

Change the region. For a non-rectangular region, delete all the text between the end points and enter insert mode. For a rectangular region, prompt for the text to fill the lines.

^A u

Change the case of the region to all uppercase.

^A l

Change the case of the region to all lowercase.

^A ~

Toggle the case of all alphabetic characters in the region.

^A SPACE

Fill the region with spaces.

p, P

Put the text back. vile does a rectangular put if the original text was rectangular.

^A p, ^A P

Force previously yanked text to be put back as if it were rectangular. The width of the longest yanked line is used for the rectangle's width.



Library Navigation Links

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