Java Reference
In-Depth Information
In both cases, when you hit the top or bottom of the file, vi will wrap and
keep searching from the opposite end, though a warning message will appear
in the status bar.
OK, enough navigation. Let's start modifying text.
Copy and paste operations can be done easily on whole lines. Just yank
and put the lines. You can yank a single line or several at a time (e.g., 7y ) and
then a single put ( p ) will deposit a copy just after the current line (the line
where your cursor sits). If you want to put the text before, not after, the current
line, use uppercase P .
Go ahead. Try it on the file you're practicing on. It's the best way to get
a feel for what we're describing here.
Cut and paste operations involve deleting the lines, not just copying them.
This gets us into our third and final kind of syntax in vi , the double letter
commands. Use dd to delete a line. Try it and you will find that the line your
cursor is on just got deleted, and the cursor now rests comfortably on the next
line. To paste that line back, use the same p or P that we used for to put the
lines that we had copied (a.k.a. “yanked”) above.
But why the dd ? What's with the double letters? Think of “delete” for d
and then add another letter to describe how much you want to delete— dw for
“delete word” or dW for “delete the bigger words” (see above). So why dd for a
line? We don't know for a fact, but we suspect that it's just for speed. You can
also follow a d with the h , j , k , or l of our cursor movement, and that will
delete either a character or a line in the appropriate direction.
A faster way (one keystroke, not two) to delete a single character is with
the x key. And of course 5x , or 27x , will delete multiple characters. But if
you're deleting many characters you will probably get it done faster by deleting
“words” ( dw or dW ).
Another powerful way to delete text is to delete it from the cursor up to a
specific character. The sequence dt; will delete from the cursor up to (but not
including) the semicolon on the current line. If there is no semicolon, vi will
beep, and no change will be made. To delete from the cursor up to and includ-
ing the semicolon, use df; .
Everything you've just learned about delete is also true for change, the c
in vi . You can combine it with itself ( cc ) to change a whole line. You can
combine it with w to change a word ( cw ), or you can change from the cursor
up to the next semicolon ( ct; ), and so on.
Search WWH ::




Custom Search