How do I undo changes back to how the file looked 5 minutes ago?
:earlier
Vim's undo history is not just a linear list of changes — it records timestamps too.
:earlier
Vim's undo history is not just a linear list of changes — it records timestamps too.
:undojoin
When writing Vim scripts or running multiple Ex commands, each command normally creates a separate undo entry.
"1p then u then . to cycle
Vim stores your last 9 deletions in numbered registers "1 through "9.
<C-g>u
By default, Vim treats an entire Insert mode session (from entering Insert mode to pressing ) as a single undo unit.
:UndotreeToggle
The undotree plugin provides a visual tree representation of Vim's undo history.
u after macro (single undo)
When a macro makes multiple changes, a single u undoes the entire macro as one unit.
:earlier 10m
The :earlier command restores the buffer to its state at a specific time in the past.
:earlier 5m
Vim's :earlier and :later commands let you travel through your undo history using time-based offsets — not just individual changes.
"1p ... "2p ... "9p
Vim maintains a numbered register history from "1 through "9 that stores your last 9 deletes and changes.
:earlier {time} / :later {time}
Vim's :earlier and :later commands let you navigate the undo history by wall-clock time rather than by individual undo steps.
editing #editing #undo-redo #ex-commands #advanced #productivity
g- / g+
Vim doesn't have a simple linear undo stack — it maintains a full undo tree with branches.
editing #editing #undo-redo #normal-mode #advanced #productivity
:set undofile
By default, Vim's undo history is lost when you close a file.
"1p then u.u.u.
Vim stores your last 9 deletions (of one line or more) in the numbered registers "1 through "9.
registers #registers #editing #normal-mode #undo-redo #paste
u
The u command undoes the last change you made in normal mode.
<C-r>
The (Ctrl+r) command redoes the last change that was undone with u.