[Quite a few vi users understand how to build vi commands with the (number)(command)(text object) model. But not too many people understand the difference between line commands and character commands. This article explains that and gives some examples. -JP]
_ (underscore) command is very similar to the
command in that it moves
to the first non-blank character of the current line. The key
difference is that
_ is a line command while
is a character
command. This is important for all functions that read an "address,"
In fact, delete, yank, and so on all call a common internal
routine in vi to get an "address." If the address is of a particular
character, vi does a character-mode delete or yank or whatever. If
it is a line address, vi does a line-mode operation. The
"address" command may be any of the regular positioning commands
/pattern/) or the original character repeated (as in
Some examples are in Table 30.1.
|dd||Deletes the current line.|
Deletes all lines between the current line and the line containing mark
Deletes all characters between the current character
and the character at mark
Changes all characters (not lines!) between the
current character up to but not including the
Changes all characters between the current character
|yj||Yanks two lines, the current line and the one below.|
Yanks all the lines from the top of the screen to the current line, inclusive.
Unindents or "dedents" the lines between the current line and the
last line, inclusive. (The variable
Runs the lines between the current line and the end of the paragraph through the program.
NOTE: If you have
wrapscanset, a search like
c?accord?may wrap from the beginning of the file to the end. This can cause unexpected results, and is one reason why I have
set nowsin my .exrc. Unfortunately, turning off
wrapscanbreaks in many versions of vi.
vi combines the repeat count, if any, on the command character with
the repeat count on the motion command, so that
2y2j yanks five
2y2_ yanks 4 lines (so does
_ command moves down (repeat count minus 1) lines. Beware,
however, of using repeat counts on all of the motion commands; they're
not all implemented in the same way.
4$ moves to the end of the third
line below the current;
4 merely moves to the first non-blank
character of the current line.
| (vertical bar) is a synonym for
0 (zero); given a repeat count it goes that many characters to the right
of the beginning of the line (as if you had typed
l). (Exercise for the reader: why can't you give a repeat count
Uppercase letters do different things depending on the command. The
exact actions may not always seem sensible, but typically they affect
the "current line":
D acts like
Y acts like
yy. The list must merely
be memorized, or you can use
a good vi reference guide.
- in net.unix on Usenet, 19 March 1984