Vi is probably the most powerful text editor for *NIX, but if you have ever tried to use it, you probably walked away frustrated. This article walks through all the capabilities and features of Vi - from the basics, such as saving and quitting, to the more advanced topics of searching for strings.
Next up, deleting and copying text. To delete a single character, position the cursor under it, make sure you're in command mode, and type
x
to delete it. To delete a word, hit
dw
which stands for "delete word". Nuking an entire line is
accomplished with
dd
while novelists with writers block will appreciate the
thoughtfulness of the
dgg
and
dG
commands, which delete everything from the current cursor
position to the beginning and end of the file respectively.
Oops - you didn't just try that last one, did you? Not to worry - vi also comes with a very handy "undo" command, which can be accessed by hitting
u
whenever you feel the urge to undo your previous mistakes.
And since undo and redo go together like strawberries and cream, you might want to check out the "redo" command, which allows you to repeat past actions by typing
. [yup, that's a period]
When you delete something in vi, the deleted text usually
finds its way to a temporary buffer in memory, where it resides until it is replaced. This deleted text can be re-inserted into your document with the "put" command; if you've been following along, you already know that the "put" command is accessed with
p
Go on - try it. Delete a line, move down to a new paragraph,
and put it back in a different place. Simple - and equivalent to the cut-paste functionality available in other editors.
In case you'd like to insert the deleted text *above* the current cursor position, simply use
P
instead of
p
What about copy-paste? Also pretty easy - vi uses the "yank"
command to copy text in much the same way as the delete command is used to delete text. To yank a particular word, try
yw
while
yy
yanks a complete line and places it in the temporary buffer,
ready to be "put" somewhere new.
You're probably wondering what all this has to do with shampoo. Absolutely nothing - this particular lesson was originally titled "Cut, Copy, Paste...", but I thought "Lather, Rinse, Repeat..." had a nicer ring to it...
This article copyright Melonfire 2000. All rights reserved.