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.
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.
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 ...
Get Learning the vi and Vim Editors, 7th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.