1 *usr_32.txt* For Vim version 7.1. Last change: 2006 Apr 30
3 VIM USER MANUAL - by Bram Moolenaar
8 Vim provides multi-level undo. If you undo a few changes and then make a new
9 change you create a branch in the undo tree. This text is about moving
12 |32.1| Numbering changes
13 |32.2| Jumping around the tree
14 |32.3| Time travelling
16 Next chapter: |usr_40.txt| Make new commands
17 Previous chapter: |usr_31.txt| Exploiting the GUI
18 Table of contents: |usr_toc.txt|
20 ==============================================================================
21 *32.1* Numbering changes
23 In section |02.5| we only discussed one line of undo/redo. But it is also
24 possible to branch off. This happens when you undo a few changes and then
25 make a new change. The new changes become a branch in the undo tree.
27 Let's start with the text "one". The first change to make is to append
28 " too". And then move to the first 'o' and change it into 'w'. We then have
29 two changes, numbered 1 and 2, and three states of the text:
41 If we now undo one change, back to "one too", and change "one" to "me" we
42 create a branch in the undo tree:
54 You can now use the |u| command to undo. If you do this twice you get to
55 "one". Use |CTRL-R| to redo, and you will go to "one too". One more |CTRL-R|
56 takes you to "me too". Thus undo and redo go up and down in the tree, using
57 the branch that was last used.
59 What matters here is the order in which the changes are made. Undo and redo
60 are not considered changes in this context. After each change you have a new
63 Note that only the changes are numbered, the text shown in the tree above has
64 no identifier. They are mostly referred to by the number of the change above
65 it. But sometimes by the number of one of the changes below it, especially
66 when moving up in the tree, so that you know which change was just undone.
68 ==============================================================================
69 *32.2* Jumping around the tree
71 So how do you get to "one two" now? You can use this command: >
75 The text is now "one two", you are below change 2. You can use the |:undo|
76 command to jump to below any change in the tree.
78 Now make another change: change "one" to "not":
94 Now you change your mind and want to go back to "me too". Use the |g-|
95 command. This moves back in time. Thus it doesn't walk the tree upwards or
96 downwards, but goes to the change made before.
98 You can repeat |g-| and you will see the text change:
104 Use |g+| to move forward in time:
111 Using |:undo| is useful if you know what change you want to jump to. |g-| and
112 |g+| are useful if you don't know exactly what the change number is.
114 You can type a count before |g-| and |g+| to repeat them.
116 ==============================================================================
117 *32.3* Time travelling
119 When you have been working on text for a while the tree grows to become big.
120 Then you may want to go to the text of some minutes ago.
122 To see what branches there are in the undo tree use this command: >
125 < number changes time ~
129 Here you can see the number of the leaves in each branch and when the change
130 was made. Assuming we are below change 4, at "not two", you can go back ten
131 seconds with this command: >
135 Depending on how much time you took for the changes you end up at a certain
136 position in the tree. The |:earlier| command argument can be "m" for minutes
137 and "h" for hours. To go all the way back use a big number: >
141 To travel forward in time again use the |:later| command: >
145 The arguments are "s", "m" and "h", just like with |:earlier|.
147 ==============================================================================
149 Next chapter: |usr_40.txt| Make new commands
151 Copyright: see |manual-copyright| vim:tw=78:ts=8:ft=help:norl: