How do I jump directly to a specific point in the undo history by change number?
Answer
:undo {N}
Explanation
:undo {N} lets you jump directly to the undo tree state after change number N was applied. Unlike pressing u which steps backward one change at a time, this lets you teleport to any recorded state — useful when you've made many changes and need to return to a specific earlier version.
How it works
:undolistdisplays all leaf states in the undo tree with their change numbers and timestamps- The
numbercolumn shows the change number to pass to:undo N :undo 0reverts to the original file state (before any changes in this session)- After jumping, you can continue editing from that point, creating a new branch in the undo tree
Example
After making several edits, run :undolist:
number changes when
3 3 2 minutes ago
7 7 1 minute ago
12 12 just now
To jump back to the state after change 7:
:undo 7
To revert the file to its original state:
:undo 0
Tips
:undolistonly shows leaf nodes of the undo tree, not every intermediate state- After
:undo N, pressinguor<C-r>continues navigating from that point - Pair with
:earlier/:laterfor time-based navigation instead of change-number-based - The
undotree()Vimscript function returns the full tree structure programmatically