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
COMMANDFUNCTION
aAdds text after the cursor
AAdds text at the end of the current line
iInserts text before the cursor
IInserts text at the beginning of the current line
oInserts a blank line after the current line
OInserts a blank line before the current line

Table 4.2. vi Commands to Delete Text
COMMANDFUNCTION
xDeletes one character (under the cursor)
XDeletes one character (behind the cursor)
ddDeletes the current line
5ddDeletes five lines starting with the current line (any number would work here)
dwDeletes the current word
cwChanges the current word (deletes it and replaces it with the next word you type)
rReplaces the character under the cursor with the next character you type
RReplaces the existing text with the text you type (like overtype mode in most word processors)

Table 4.3. Other Handy vi Editing Commands
COMMANDFUNCTION
yyCopies the current line
pPastes the copied line after the cursor or line
JJoins the current and following lines
uUndoes the last change
UUndoes all changes on the current line
.Repeats the last command

To Add or Delete Text in vi:

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.
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.

6.
dd

Type the command. Here, we’re deleting the current line of text.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.73.35