• Keine Ergebnisse gefunden

Repeating Actions with the . Command

Im Dokument XE 500 (Seite 169-174)

Vi provides a time saving command, called the "dot"

command. You can repeat the last action by placing the cursor at the location you wish to repeat the last action and typing a:

The following actions can be repeated using the dot (.) command.

o Append.

o Insert.

o Open.

o Delete.

o Change.

o Put.

The following paragraphs illustrate how each of the above actions can be repeated using the (.) command.

When you append text at a location and press the GO key, it may be necessary to add this same text to another location.

In this case, move the cursor to the character that you desire the text to follow and type a dot.

When you insert text and press the GO key, move the cursor to the character that you desire the text to precede and type a dot. When you have opened a new line, added new text, and pressed the GO key, move the cursor to the line where the new text is to be repeated and one of the following will occur when you type a dot. If you had opened the original line using a lowercase 0, the repeated text will be added following the line your cursor is on. If you had opened the original line using an uppercase 0, the repeated text will be added preceding the line your cursor is on.

After you have deleted text by using an x, dd, 0 or a delete with an object command, move the cursor to another location;

and by typing a dot, repeat this same command. For example, if you give the command delete two words by typing d2w, the two words you desire to remove are deleted.

You can now move the cursor to the first character of two different words and type a dot and the two new words will be deleted.

After you have changed text by using an r, 5, S, , cc, C, or a change with an object command, move the cursor to another location; and by typing a dot, place the same text added by the previous change command. For example, if you give the command change two lines by typing 2cc and type in some text, the line you are on and the next line is replaced by the new text. You can now move your cursor to another line and type a dot. The line your cursor is on and the next line will be replaced by the text added in the last change.

After you have executed a put command that is associated with the unnamed register and if you desire to place this text at another location, the text in the unnamed register may not be the same. In most cases, you cannot use the dot (.) command to place the original text at the new location.

If you desire to place text at another location that is in a named register after doing a put, you can save time by using the dot (.) command instead of having to repeat the register name.

Example Eight

1 Access the file containing the text at the end of Example Five:

$ vi f I I ename

2 Move the cursor to the "n" in "When" in the first line of the first paragraph.

3 Append to this word by typing an a followed by a space, five x's, and press the GO key:

a xxxxx

Five x's now follow When.

4 Move the cursor to the "d" in "located" in the sixth line of the first paragraph. Append the five x's by typing the following:

The five x's just added could be a word you wish to repeat.

5 Move the cursor to the "d" in "command" in the eighth line of the first paragraph and type the following:

The five x's are appended for the second time.

6 Move the cursor to the "e" in "except" in the tenth line of the first paragraph.

7 Insert two lines of y's by typing the following and pressing the GO key:

iyyyyy (Press the RETURN key) yyyyy

7 The line is split with five y's at the end of the first line and five y's preceding the second line.

8 Move the cursor to the "t" in "them" in the last line of the first paragraph.

9 Insert the two lines of y's by typing the following:

The line splits with five y's at the end of the first line and five y's preceding "them" on the second line.

10 Move the cursor to any character in the first line of the second paragraph.

11 Add a line of text to follow this line by typing the following and pressing the GO key:

ozzzzzzzzzz

A blank line opens after the first line and ten z' s are added to this line.

12 Move the cursor to any character in the first line of the third paragraph.

13 Add the ten z's by typing the following:

The ten z' s are added on a new line following the line the cursor is on.

1~ Delete the ten z's on this line by typing the following:

dd

The z' s disappear and the lines close up.

15 Move the cursor to the last line in the third paragraph.

16 Delete this line by using the dot (,) command.

The last line disappears and the file closes up.

17 Move the cursor the "d" in "directory" in the third sentence of the fourth paragraph.

18 Change this word to "location" by typing the following and pressing the GO key:

cwlocation

19 Locate each of the remaining occurrences of "directory" in this paragraph and by using the dot (.) command change the word to "location."

Note that the cursor must be placed on the "d" to make the correct change. Observe that another change must be made to change "directories."

20 Move the cursor to the "B" in "Because" in the eighth line in the fourth paragraph.

21 Yank the remainder of this line and the next two lines by typing the following:

y3$

22 Move the cursor to the space before "The" in the third paragraph.

23 Insert the three lines just yanked by typing a lowercase p.

p

24 Move the cursor to the space before "You" near the end of the first paragraph.

25 Attempt to enter the three lines added in the previous step by typing a dot.

Wrong text. The same thing would have happened if you had entered another p. This is a good reason for using a named register. When using a named register, the text can be copied in a number of locations using the . or a "xp.

The . can be used only to repeat the last "xp.

26 Exit your file without writing the changes just made by typing the following and pressing the RETURN key:

: q I

Im Dokument XE 500 (Seite 169-174)