How to undo and redo in Vim
uCtrl-rPress u in Normal mode to undo the last change. Press Ctrl-r to redo it.
Everything you type between entering Insert mode and pressing Esc is one change, so one u removes all of it. A command with a count, such as 3x, is one change too.
Worked example
Type wrong before note, undo it, then redo it.
After u the text is note again. Ctrl-r brings the insertion back in one step.
Commands
- u
- Undo the last change.
- Ctrl-r
- Redo the change you undid.
- 2u
- Undo the last two changes.
Exceptions
- Moving the cursor is not a change. After x, then w, one u still restores the deleted letter.
- A counted command is one change: after 3x, one u restores all three letters.
- Undo only works in Normal mode. Press Esc first; in Insert mode, u types a
u. - To cancel a command you have started, such as d waiting for a motion, press Esc. Nothing changes, so there is nothing to undo.