Cover by Linda Lamb, Elbert Hannah, Arnold Robbins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

Simple Edits

When you enter text in your file, it is rarely perfect. You find typos or want to improve on a phrase; sometimes your program has a bug. Once you enter text, you have to be able to change it, delete it, move it, or copy it. Figure 2-3 shows the kinds of edits you might want to make to a file. The edits are indicated by proofreading marks.

Proofreading edits
Figure 2-3. Proofreading edits

In vi you can perform any of these edits with a few basic keystrokes: i for insert (which you’ve already seen); a for append; c for change; and d for delete. To move or copy text, you use pairs of commands. You move text with a d for “delete,” then a p for “put”; you copy text with a y for “yank,” then a p for “put.” Each type of edit is described in this section. Figure 2-4 shows the vi commands you use to make the edits marked in Figure 2-3.

Edits with vi commands
Figure 2-4. Edits with vi commands

Inserting New Text

You have already seen the insert command used to enter text into a new file. You also use the insert command while editing existing text to add missing characters, words, and sentences. In the file practice, suppose you have the sentence:

 you can scroll
 the page, move the cursor, deletelines, and insert characters.

with the cursor positioned as shown. To insert With a screen editor at the beginning of the sentence, enter ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required