editing
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.
u <C-r> (normal mode) Variations
| Keystroke | Effect |
|---|---|
| 5u | Undo the last 5 changes |
| U | Undo ALL changes on the current line (not a step-back — different feature) |
| g- | Go to older text state (undo branch) |
| g+ | Go to newer text state |
Examples
u Undo last change
<C-r> Redo (re-apply what u just undid)
:earlier 5m Roll file state back 5 minutes
Gotcha
One 'change' is everything you did between two Escapes in insert mode — a whole paragraph typed in one insert is a single u. If you leave insert mode often, you get finer-grained undo.
Related
.
Repeats the last CHANGE (any command that modified the buffer, including the whole insert-mode session that followed it). The single most-loved Vim feature — learn to structure edits so that '.' does the work for the next N occurrences.
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.
Escape
Leaves the current mode and returns to normal mode. Vim is modal — most of the time you want to be in normal mode; if you're not sure what mode you're in, mash Escape.
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.
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.