- Choosing an Editor
- Starting pico and Dabbling with It
- Saving in pico
- Cutting and Pasting Text Blocks in pico
- Checking Spelling in pico
- Getting Help in pico
- Exiting pico
- Starting vi and Dabbling with It
- Saving in vi
- Adding and Deleting Text in vi
- Importing Files into vi
- Searching and Replacing in vi
- Exiting vi
- Starting emacs and Dabbling with It
- Using emacs Menus to Spell-Check
- Saving in emacs
- Exiting emacs
Adding and Deleting Text in vi
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.
Table 4.1. vi Commands to Add Text
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 |
Table 4.2. vi Commands to Delete Text
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 enters input mode) |
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) |
Table 4.3. Other Handy vi Editing Commands
COMMAND |
FUNCTION |
yy |
Copies the current line |
p |
Pastes any copied text after the cursor or line |
J |
Joins the current and following lines |
u |
Undoes the last change |
U |
Undoes all changes on the current line |
. |
Repeats the last command |
To add or delete text in vi:
vi
To begin, type vi at the shell prompt.
i
Change into input mode.
There once was a man from Nantucket
Type some text that you'll want to add to.
-
Press to enter command mode before you issue the commands.
Choose a command, based on what you want to do to the text.
Table 4.1 lists commands to add text.
Table 4.2 lists commands to delete text.
Table 4.3 lists miscellaneous editing commands.
dd
Type the command. Here, we're deleting the current line of text.