How do I undo the last change in Vim?
Answer
u
Explanation
The u command undoes the last change you made in normal mode. Vim maintains a full undo history, so you can press u repeatedly to step back through every change you have made since opening the file.
How it works
ureverses the most recent change- Each press of
usteps one change further back in history - Vim tracks undo history as a tree, not just a linear stack
Example
Given the text:
Hello world
You change world to Vim using ciwVim<Esc>, resulting in:
Hello Vim
Pressing u reverts it back to:
Hello world
Tips
- Use
Uto undo all changes on the current line (less commonly used) - Use
<C-r>to redo (reverse an undo) - Use
:earlier 5mto jump back to the state from 5 minutes ago - Use
:later 5mto jump forward in time - Vim's undo is a tree — if you undo and then make a new change, the old branch is preserved and accessible with
g-andg+ - Use
:undolistto see the undo branches available