vimtricks.wiki Concise Vim tricks, one at a time.

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

  • :undolist displays all leaf states in the undo tree with their change numbers and timestamps
  • The number column shows the change number to pass to :undo N
  • :undo 0 reverts 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

  • :undolist only shows leaf nodes of the undo tree, not every intermediate state
  • After :undo N, pressing u or <C-r> continues navigating from that point
  • Pair with :earlier / :later for time-based navigation instead of change-number-based
  • The undotree() Vimscript function returns the full tree structure programmatically

Next

How do I highlight all occurrences of a yanked word without typing a search pattern?