Training plan › Editing

Copy and paste

yy, p, P and the line-swap trick.

Copying in Vim is called yank: yy copies the line, yw a word, y + motion whatever you want. Paste is p (after) or P (before). Deleting also “copies”: what you remove with dd or x goes to the same place, so ddp swaps two lines.

5 steps · 4 min · 60 XP

  1. Copy and paste a line: yyp
  2. Paste above: P
  3. Swap lines: ddp
  4. Copy a word and replace another
  5. Paste several times: 3p

Create a free account