1702
|
1 *usr_32.txt* For Vim version 7.2. Last change: 2006 Apr 30
|
799
|
2
|
|
3 VIM USER MANUAL - by Bram Moolenaar
|
|
4
|
|
5 The undo tree
|
|
6
|
|
7
|
|
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
|
|
10 through the branches.
|
|
11
|
|
12 |32.1| Numbering changes
|
|
13 |32.2| Jumping around the tree
|
|
14 |32.3| Time travelling
|
|
15
|
|
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|
|
|
19
|
|
20 ==============================================================================
|
|
21 *32.1* Numbering changes
|
|
22
|
|
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.
|
|
26
|
|
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:
|
|
30
|
|
31 one ~
|
|
32 |
|
|
33 change 1
|
856
|
34 |
|
799
|
35 one too ~
|
856
|
36 |
|
799
|
37 change 2
|
856
|
38 |
|
799
|
39 one two ~
|
|
40
|
|
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:
|
|
43
|
|
44 one ~
|
|
45 |
|
|
46 change 1
|
856
|
47 |
|
799
|
48 one too ~
|
|
49 / \
|
856
|
50 change 2 change 3
|
|
51 | |
|
|
52 one two me too ~
|
799
|
53
|
|
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.
|
|
58
|
|
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
|
|
61 state of the text.
|
|
62
|
|
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.
|
|
67
|
|
68 ==============================================================================
|
|
69 *32.2* Jumping around the tree
|
|
70
|
|
71 So how do you get to "one two" now? You can use this command: >
|
|
72
|
|
73 :undo 2
|
|
74
|
|
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.
|
|
77
|
|
78 Now make another change: change "one" to "not":
|
|
79
|
|
80 one ~
|
|
81 |
|
|
82 change 1
|
856
|
83 |
|
799
|
84 one too ~
|
|
85 / \
|
856
|
86 change 2 change 3
|
|
87 | |
|
|
88 one two me too ~
|
799
|
89 |
|
|
90 change 4
|
|
91 |
|
|
92 not two ~
|
|
93
|
|
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.
|
|
97
|
|
98 You can repeat |g-| and you will see the text change:
|
|
99 me too ~
|
|
100 one two ~
|
|
101 one too ~
|
|
102 one ~
|
|
103
|
|
104 Use |g+| to move forward in time:
|
|
105 one ~
|
|
106 one too ~
|
|
107 one two ~
|
|
108 me too ~
|
|
109 not two ~
|
|
110
|
|
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.
|
|
113
|
|
114 You can type a count before |g-| and |g+| to repeat them.
|
|
115
|
|
116 ==============================================================================
|
|
117 *32.3* Time travelling
|
|
118
|
|
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.
|
|
121
|
|
122 To see what branches there are in the undo tree use this command: >
|
|
123
|
|
124 :undolist
|
|
125 < number changes time ~
|
|
126 3 2 16 seconds ago
|
|
127 4 3 5 seconds ago
|
|
128
|
|
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: >
|
|
132
|
|
133 :earlier 10s
|
|
134
|
|
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: >
|
|
138
|
|
139 :earlier 10h
|
|
140
|
|
141 To travel forward in time again use the |:later| command: >
|
|
142
|
|
143 :later 1m
|
|
144
|
|
145 The arguments are "s", "m" and "h", just like with |:earlier|.
|
|
146
|
|
147 ==============================================================================
|
|
148
|
|
149 Next chapter: |usr_40.txt| Make new commands
|
|
150
|
|
151 Copyright: see |manual-copyright| vim:tw=78:ts=8:ft=help:norl:
|