The Cut, Copy, and Paste Commands
The process of moving text around in vi is a little complex, so practice on a scratch file first. The following keystrokes are used to cut, copy, and paste text in a vi session:
yyCopies a line of text to the unnamed buffer
3yyCopies three lines of text to the unnamed buffer
ywCopies a word (under the cursor) to the unnamed buffer
3ywCopies three words to the unnamed buffer
pPastes the contents of the unnamed buffer to the right of the cursor
PPastes the contents of the unnamed buffer to the left of the cursor
Yanking (or copying) lines (the y key) and pasting (the p key) them back in are done on a whole-line basis, whereas yanking a word or several words is done solely on a word basis. Pasting data back in happens to the right of the current cursor position, so take care to put the cursor directly to the left of the desired insertion point. Pasting puts lines as a new entry directly below the current cursor line.
A common use of the cut, copy, and paste commands is in the /etc/fstab file when you've added another file system or disk. Open the file, find a line similar to the desired new one, and press yy; then move the cursor to the line above the position you desire for the line, then press yy. The yanked line will appear under the current cursor line.