How do I undo all changes made since the last time I saved the file in a single step?
:earlier 1f
The :earlier {count}f command navigates Vim's undo tree to the state of the buffer at the time of the last (or Nth) file write.
:earlier 1f
The :earlier {count}f command navigates Vim's undo tree to the state of the buffer at the time of the last (or Nth) file write.
inoremap <Left> <C-g>U<Left>
In insert mode, any cursor movement — including arrow keys, Home, and End — causes Vim to split the undo block at that point.
g+ and g-
Vim's undo history is a tree, not a linear stack.
"1p
Vim automatically stores your deletion history in numbered registers "1 through "9.
"1p then u. to cycle through delete history
Vim silently maintains a rolling history of your last 9 deletions in numbered registers "1 through "9.
: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.