Like most modern applications, VIM has an undo/redo feature. As you’re
typing along, you might realize that you’ve made a mistake and you want
to undo it. This is easy. In command mode, type:
u
and VIM will undo your latest changes. If you decided that you really
did mean to make those changes, type:
<CTRL>+r
or
:redo
And the last change will be restored.
But VIM doesn’t just store a linear stack of changes. Often, the
changes you make will cause branches in the document’s change history,
and VIM can help you navigate these changes. If you type:
:undolist
You’ll see a not-very-user-friendly list of information in three
columns. The first column is the change number, which is the branch’s
ID; the second is the number of changes that occurred in that branch,
and the third is the time the branch was created.
The branch IDs are sequential, so if you remember the order in which
changes were made, you can type:
:undo <ID>
to jump back to a specific branch. But because the time stamps are
included for each branch, you can also use the commands
:earlier
and
:later
:earlier and :later take an argument of minutes, seconds, or hours. So
if you made a change ten minutes ago and you want to revert to it, you
can type:
:earlier 10m
And from there,
:later 5m
You can also use the following commands to scroll backwards and forwards
through all change branches:
:g-
:g+
Happy VIMming!
- David Roth
