editing
yy
'Yank' (copy) the current line into the unnamed register — Vim's word for copy. Combine with p/P to duplicate lines without touching your system clipboard.
yy (normal mode) Variations
| Keystroke | Effect |
|---|---|
| 3yy | Yank 3 lines starting from current |
| y$ or Y | Yank from cursor to end of line (Y differs from D/C, which act line-wise) |
| yw | Yank to start of next word |
| "+yy | Yank line into the system clipboard (needs +clipboard build) |
Examples
yy Copy current line
5yyp Copy 5 lines and paste them below
"+yy Copy current line to system clipboard
Gotcha
Historical wart: Y in stock Vim behaves like yy (yank whole line), not y$. Many people remap Y to y$ to match D and C — check your config.
Related
dd
Deletes the current line (and stores it in the unnamed register, so you can paste it back with p). The bread-and-butter 'get rid of this line' command.
p / P
Paste the contents of the unnamed register: p pastes AFTER the cursor (or below the line, for a linewise yank), P pastes BEFORE the cursor (or above the line). Works with anything you dd'd, yy'd, or x'd.
v / V / Ctrl-V
v enters character-wise visual mode, V enters line-wise visual mode, and Ctrl-V enters visual BLOCK (column/rectangle) mode. Once selected, operators like d, y, c, or > act on the whole region.
i / a / o / O
The four ways to enter insert mode: i inserts BEFORE the cursor, a inserts AFTER it, o opens a new line BELOW and enters insert mode, O opens a new line ABOVE. Choosing the right one saves a motion or two before you start typing.
u / Ctrl-R
u undoes the last change; Ctrl-R redoes it. Vim has a full undo TREE (see :undolist and g-/g+) but for day-to-day work these two keys are enough.