Miscellaneous Commands

Several miscellaneous commands round out vi-mode; some of them are quite esoteric. They are listed in Table 2-14.

Table 2-14. Miscellaneous vi-mode commands

广告:个人专属 VPN,独立 IP,无限流量,多机房切换,还可以屏蔽广告和恶意软件,每月最低仅 5 美元

Command

Description

~

Invert (twiddle) case of current character(s)

-

Append last word of previous command, enter input mode

CTRL-L

Clear the screen and redraw the current line on it; good for when your screen becomes garbled

#

Prepend # (comment character) to the line and send it to the history list; useful for saving a command to be executed later without having to retype it[8]

[8] The line is also "executed" by the shell. However, # is the shell's comment character, so the shell ignores it.

The first of these can be preceded by a repeat count. A repeat count of n preceding the ~ changes the case of the next n characters. The cursor will advance accordingly.

A repeat count preceding _ causes the nth word in the previous command to be inserted in the current line; without the count, the last word is used. Omitting the repeat count is useful because a filename is usually the last thing on a UNIX command line, and because users often run several commands in a row on the same file. With this feature, you can type all of the commands (except the first) followed by ESC-_, and the shell will insert the filename.

 


[5] In particular, versions of UNIX derived from 4.x BSD have all of these commands built in.

[6] Neither of these definitions is the same as the definition of a word in emacs-mode.

[7] Fans of vi and search utilities like grep should note that caret (^) for beginning-of-line is the only context operator vi-mode provides for search strings.