Adding and deleting text in vi is a bit more complicated than doing the same in pico. Whereas in pico, you basically just place your cursor where you want to make changes, vi has a whole slew of commands that you use to specify where the changes should occur. (Tables 4.1, 4.2, and 4.3 list only a very few of your options.) Plus, to issue the commands, you have to switch to command mode.
COMMAND | FUNCTION |
---|---|
a | Adds text after the cursor |
A | Adds text at the end of the current line |
i | Inserts text before the cursor |
I | Inserts text at the beginning of the current line |
o | Inserts a blank line after the current line |
O | Inserts a blank line before the current line |
COMMAND | FUNCTION |
---|---|
x | Deletes one character (under the cursor) |
X | Deletes one character (behind the cursor) |
dd | Deletes the current line |
5dd | Deletes five lines starting with the current line (any number would work here) |
dw | Deletes the current word |
cw | Changes the current word (deletes it and replaces it with the next word you type) |
r | Replaces the character under the cursor with the next character you type |
R | Replaces the existing text with the text you type (like overtype mode in most word processors) |
1. | vi To begin, type vi at the shell prompt. |
2. | i Change into input mode. |
3. | There once was a man from Nantucket Type in some text that you’ll want to add to. |
4. | Press to enter command mode before you issue the commands. |
5. | |
6. | dd Type the command. Here, we’re deleting the current line of text. |