Partially synced with the branch.
[MacVim.git] / runtime / doc / usr_32.txt
blob852c7c8bce8b4d6411107ef298feb2998b7fdb2b
1 *usr_32.txt*    For Vim version 7.2c.  Last change: 2006 Apr 30
3                      VIM USER MANUAL - by Bram Moolenaar
5                               The undo tree
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.
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:
31                 one ~
32                  |
33               change 1
34                  |
35               one too ~
36                  |
37               change 2
38                  |
39               one two ~
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:
44                 one ~
45                  |
46               change 1
47                  |
48               one too ~
49               /     \
50          change 2  change 3
51             |         |
52          one two    me too ~
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
61 state of the text.
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: >
73         :undo 2
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":
80                 one ~
81                  |
82               change 1
83                  |
84               one too ~
85               /     \
86          change 2  change 3
87             |         |
88          one two    me too ~
89             |
90          change 4
91             |
92          not two ~
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:
99         me too ~
100         one two ~
101         one too ~
102         one ~
104 Use |g+| to move forward in time:
105         one ~
106         one too ~
107         one two ~
108         me too ~
109         not two ~
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: >
124         :undolist
125 <       number changes  time ~
126              3       2  16 seconds ago
127              4       3  5 seconds ago
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: >
133         :earlier 10s
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: >
139         :earlier 10h
141 To travel forward in time again use the |:later| command: >
143         :later 1m
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: