OnWorks Linux and Windows Online WorkStations

Logo

Free Hosting Online for WorkStations

< Previous | Contents | Next >

Cutting, Copying, And Pasting Text

The d command not only deletes text, it also “cuts” text. Each time we use the d com- mand the deletion is copied into a paste buffer (think clipboard) that we can later recall with the p command to paste the contents of the buffer after the cursor or the P command to paste the contents before the cursor.

The y command is used to “yank” (copy) text in much the same way the d command is


used to cut text. Here are some examples combining the y command with various move- ment commands:


Table 12- 4: Yanking Commands


Command Copies

Command Copies

yy The current line.


image

5yy The current line and the next four lines.


image

yW From the current cursor position to the beginning of the next word.


image

y$ From the current cursor location to the end of the current line.


image

y0 From the current cursor location to the beginning of the line.


image

y^ From the current cursor location to the first non- whitespace character in the line.


image

yG From the current line to the end of the file.


image

y20G From the current line to the twentieth line of the file.


image


Let's try some copy and paste. Place the cursor on the first line of the text and type yy to copy the current line. Next, move the cursor to the last line (G) and type p to paste the line below the current line:



The quick brown fox jumped over the lazy dog. It was cool. Line 2

Line 3

Line 4

Line 5

The quick brown fox jumped over the lazy dog. It was cool.

The quick brown fox jumped over the lazy dog. It was cool. Line 2

Line 3

Line 4

Line 5

The quick brown fox jumped over the lazy dog. It was cool.


Just as before, the u command will undo our change. With the cursor still positioned on the last line of the file, type P to paste the text above the current line:


The quick brown fox jumped over the lazy dog. It was cool. Line 2

Line 3

Line 4

The quick brown fox jumped over the lazy dog. It was cool. Line 2

Line 3

Line 4


The quick brown fox jumped over the lazy dog. It was cool.

Line 5

The quick brown fox jumped over the lazy dog. It was cool.

Line 5


Try out some of the other y commands in the table above and get to know the behavior of both the p and P commands. When you are done, return the file to its original state.


Top OS Cloud Computing at OnWorks: