editing
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.
dd (normal mode) Variations
| Keystroke | Effect |
|---|---|
| 3dd | Delete 3 lines starting from the current |
| d$ or D | Delete from cursor to end of line |
| d0 | Delete from cursor to start of line |
| dw | Delete to start of next word |
| "_dd | Delete WITHOUT overwriting the yank register (black-hole register) |
Examples
dd Delete the current line
5dd Delete 5 lines starting here
ddp Classic swap-lines trick: delete this line then paste it below (swaps with next line)
Gotcha
dd is a CUT, not a delete — the line goes onto the yank register and will overwrite whatever you last yanked. Use "_dd if you want to preserve your yank.
Related
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.
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.
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.
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.
x
Deletes the character under the cursor — Vim's equivalent of the Delete key. It's a cut, so the character lands in the unnamed register.