Home > Articles

Basic vi Skills

  • Print
  • + Share This
This chapter is from the book

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:

  • yy—Copies a line of text to the unnamed buffer

  • 3yy—Copies three lines of text to the unnamed buffer

  • yw—Copies a word (under the cursor) to the unnamed buffer

  • 3yw—Copies three words to the unnamed buffer

  • p—Pastes the contents of the unnamed buffer to the right of the cursor

  • P—Pastes 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.

  • + Share This
  • 🔖 Save To Your Account