How to copy and paste in Vim
In Normal mode, yy copies the line and yiw the word under the cursor; move to where it goes and press p to paste after the cursor or P before it. To cut, delete instead: dd or dw, then p.
Copy a word, cut a line
First copy: the cursor is on text. yiw yanks the word, j goes down, f) finds the bracket, and P puts the word before it. Then cut: the stray import at the bottom goes to the top, with G, dd, gg and P.
This editor needs a keyboard. Read on, and play it at your computer.
| Keys | What it does |
|---|---|
| yy | Copy the whole line. |
| 3yy | Copy three lines, starting with this one. |
| yw | Copy from the cursor to the start of the next word. |
| yiw | Copy the word under the cursor, wherever in the word you are. |
| y$ | Copy to the end of the line. |
| yap | Copy the paragraph, and the blank line after it. |
| p / P | Paste after / before the cursor. Whole lines go below / above the current line. |
| 3p | Paste three copies. |
| dd / dw / x | Cut the line / the word / the character under the cursor. |
| v or V, then y or d | Copy or cut exactly what you selected (characters with v, whole lines with V). |
| gp / gP | Paste like p / P, but leave the cursor just after the pasted text. |
Why it is called yank
Vim has its own words for it: copying is yanking and pasting is putting. With c already taken by change, copy got y, for yank. The rest follows the same pattern as every other Vim command: an operator, then what it acts on. y takes the same motions and text objects as d and c, so yw copies a word just as dw deletes one, and yi( copies what's inside the brackets.
Copying never changes the screen, and the cursor stays put (or moves to the start of what you copied). The text waits in a register until you paste it.
Cut is delete
There's no separate cut command, because every delete is a cut. dd, dw, x, and d in Visual mode all put what they removed in the same register that y fills, so p pastes it back wherever you like. That's how xp swaps two letters and ddp swaps two lines.
What you copied as whole lines pastes as whole lines: p opens a new line below the current one, whatever column the cursor is in. A word or part of a line pastes into the line, right after the cursor.
Not the system clipboard
By default, y and p use Vim's own register, not the clipboard other programs share, so text yanked in Vim won't paste into your browser with Cmd-V or Ctrl-V. "+y copies to the system clipboard and "+p pastes from it, when your Vim is built with clipboard support.