*usr_32.txt* Nvim
VIM USER MANUAL - by Bram Moolenaar
The undo tree
Vim provides multi-level undo. If you undo a few changes and then make a new
change you create a branch in the undo tree. This text is about moving
through the branches.
|32.1| Undo up to a file write
|32.2| Numbering changes
|32.3| Jumping around the tree
|32.4| Time travelling
Next chapter: |usr_40.txt| Make new commands
Previous chapter: |usr_31.txt| Exploiting the GUI
Table of contents: |usr_toc.txt|
==============================================================================
*32.1* Undo up to a file write
Sometimes you make several changes, and then discover you want to go back to
when you have last written the file. You can do that with this command: >
:earlier 1f
The "f" stands for "file" here.
You can repeat this command to go further back in the past. Or use a count
different from 1 to go back faster.
If you go back too far, go forward again with: >
:later 1f
Note that these commands really work in time sequence. This matters if you
made changes after undoing some changes. It's explained in the next section.
Also note that we are talking about text writes here. For writing the undo
information in a file see |undo-persistence|.
==============================================================================
*32.2* Numbering changes
In section |02.5| we only discussed one line of undo/redo. But it is also
possible to branch off. This happens when you undo a few changes and then
make a new change. The new changes become a branch in the undo tree.
Let's start with the text "one". The first change to make is to append
" too". And then move to the first 'o' and change it into 'w'. We then have
two changes, numbered 1 and 2, and three states of the text:
one ~
|
change 1
|
one too ~
|
change 2
|
one two ~
If we now undo one change, back to "one too", and change "one" to "me" we
create a branch in the undo tree:
one ~
|
change 1
|
one too ~
/ \
change 2 change 3
| |
one two me too ~
You can now use the |u| command to undo. If you do this twice you get to
"one". Use |CTRL-R| to redo, and you will go to "one too". One more |CTRL-R|
takes you to "me too". Thus undo and redo go up and down in the tree, using
the branch that was last used.
What matters here is the order in which the changes are made. Undo and redo
are not considered changes in this context. After each change you have a new
state of the text.
Note that only the changes are numbered, the text shown in the tree above has
no identifier.