Many word processors allow you to “copy and paste” and “cut and paste” lines of text. The vi editor also includes these features. The vi command-mode equivalent of “copy and paste” is yank and put. The equivalent of “cut and paste” is delete and put.
The methods for copying or moving small blocks of text in vi involves the use of a combination of the yank, delete, and put commands.
To yank one line, follow these steps.
Position the cursor anywhere on the line you want to yank.
Move the cursor to the line above where you want to put (copy) the yanked line.
A copy of the yanked line appears in a new line below the cursor.
To place the yanked line in a new line above the cursor, type P.
The yy command works well with a count: to yank 11 lines, for example, type 11yy. Eleven lines, counting down from the cursor, are yanked, and vi indicates this with a message at the bottom of the screen: 11 lines yanked.
To move one line, position the cursor anywhere on the line and type dd. For example, to delete 5 lines, type 5dd.
Next, move the cursor to the line above where you want the deleted line reinserted and type p. This inserts the text on a new line below the cursor.
Alternatively, you can put the deleted line above the cursor by typing P.