How do I visualize and navigate Vim's undo tree?
Answer
:UndotreeToggle
Explanation
The undotree plugin provides a visual tree representation of Vim's undo history. This makes it easy to navigate branches that normal u/<C-r> might miss.
How it works
:UndotreeToggleopens/closes the undo tree panel- Navigate the tree to see different undo states
- Select a state to restore the buffer to that point
Example
After editing a file with multiple undo/redo paths, :UndotreeToggle shows:
3 --- 4
| |
2 5
| |
1 6 (current)
Click on node 4 to restore that state.
Tips
- Install:
Plug 'mbbill/undotree' - Map it:
nnoremap <leader>u :UndotreeToggle<CR> - Works with persistent undo (
:set undofile) - Shows timestamps for each undo state
- Press
?in the tree for help on navigation