Adding and Deleting Text in vi


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


Table 4.3. Other Handy vi Editing Commands

COMMAND

FUNCTION

yy

Copies the current line

p

Pastes the copied line 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:

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.




Unix(c) Visual Quickstart Guide
UNIX, Third Edition
ISBN: 0321442458
EAN: 2147483647
Year: 2006
Pages: 251

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net