Undo and Redo
u to undo. Ctrl-R to redo. Experiment without fear.
u undoes the last change. Ctrl-R redoes it. Repeat either command to walk through multiple changes, and experiment without fear.
Undo is your permission to experiment. Try the unfamiliar motion. Run the command whose effect you cannot predict. If it changes the wrong text, press u. If you decide that the change was right after all, press Ctrl-R. You do not need to understand every command before trying it.
| Key | Note |
|---|---|
| u |
| Key | Note |
|---|---|
| {key:Ctrl-R} |
Press u repeatedly to walk backward through multiple changes. Press Ctrl-R repeatedly to walk forward again. Counts work too: 5u undoes the last five changes. Make a mess on purpose, undo it, and keep going. Fearlessness is a practical Vim skill.
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 |
Worked example โ u and Ctrl-R
Undo, then redo.
Undo and redo navigate the change history. Vim keeps a tree, not just a stack โ see undo-tree.
See also: Undo as a Tree, Repeat Last Change, Open, Save, Quit