Undo and Redo

u to undo. Ctrl-R to redo. You cannot lose work.

Keys: u, Ctrl-R, U

u undoes the last change. Ctrl-R redoes it. Vim's undo is a tree, not a stack โ€” you literally cannot lose work.

Vim is safe. Whatever you just did, you can undo. Whatever you just undid, you can redo. There is no "oh no" key โ€” only u.

Undo last change
KeyNote
u
Redo (the change you just undid)
KeyNote
Ctrl-R

Press u repeatedly to undo further. Press Ctrl-R repeatedly to redo. Counts work too: 5u undoes the last five changes.

Undo with u
Redo with Ctrl-R

U โ€” undo the line

U (capital) is a less-common command: it undoes all changes on the current line since you last moved off it. Useful occasionally; the regular u is what you'll use 99% of the time.


Reference

Key Action
u Undo last change
Ctrl-R Redo last undone change
U Undo all changes on the current line
{n}u Undo last n changes
g- Earlier in time (across branches)
g+ Later in time
:earlier {N}m Jump back N minutes
:later {N}s Jump forward N seconds

Worked example โ€” u and Ctrl-R

Undo, then redo.

Step 1 ยท
survival.undo-redo
Step 2 ยท dd ยท dd deletes 'bravo'.
dd deletes 'bravo'.
Step 3 ยท u ยท u โ€” bravo back.
u โ€” bravo back.
Step 4 ยท Ctrl-R ยท Ctrl-R โ€” redo (gone again).
Ctrl-R โ€” redo (gone again).

Undo and redo navigate the change history. Vim keeps a tree, not just a stack โ€” see undo-tree.

โ–ถ Try this in the simulator

See also: Undo as a Tree, Repeat Last Change, Open, Save, Quit