robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
7e778205ab
master
1*usr_32.txt* Nvim 2 3 4 VIM USER MANUAL by Bram Moolenaar 5 6 7 The undo tree 8 9 10Vim provides multi-level undo. If you undo a few changes and then make a new 11change you create a branch in the undo tree. This text is about moving 12through the branches. 13 14|32.1| Undo up to a file write 15|32.2| Numbering changes 16|32.3| Jumping around the tree 17|32.4| Time travelling 18 19 Next chapter: |usr_40.txt| Make new commands 20 Previous chapter: |usr_31.txt| Exploiting the GUI 21Table of contents: |usr_toc.txt| 22 23============================================================================== 24*32.1* Undo up to a file write 25 26Sometimes you make several changes, and then discover you want to go back to 27when you have last written the file. You can do that with this command: > 28 29 :earlier 1f 30 31The "f" stands for "file" here. 32 33You can repeat this command to go further back in the past. Or use a count 34different from 1 to go back faster. 35 36If you go back too far, go forward again with: > 37 38 :later 1f 39 40Note that these commands really work in time sequence. This matters if you 41made changes after undoing some changes. It's explained in the next section. 42 43Also note that we are talking about text writes here. For writing the undo 44information in a file see |undo-persistence|. 45 46============================================================================== 47*32.2* Numbering changes 48 49In section |02.5| we only discussed one line of undo/redo. But it is also 50possible to branch off. This happens when you undo a few changes and then 51make a new change. The new changes become a branch in the undo tree. 52 53Let's start with the text "one". The first change to make is to append 54" too". And then move to the first 'o' and change it into 'w'. We then have 55two changes, numbered 1 and 2, and three states of the text: 56 57 one ~ 58 | 59 change 1 60 | 61 one too ~ 62 | 63 change 2 64 | 65 one two ~ 66 67If we now undo one change, back to "one too", and change "one" to "me" we 68create a branch in the undo tree: 69 70 one ~ 71 | 72 change 1 73 | 74 one too ~ 75 / \ 76 change 2 change 3 77 | | 78 one two me too ~ 79 80You can now use the |u| command to undo. If you do this twice you get to 81"one". Use |CTRL-R| to redo, and you will go to "one too". One more |CTRL-R| 82takes you to "me too". Thus undo and redo go up and down in the tree, using 83the branch that was last used. 84 85What matters here is the order in which the changes are made. Undo and redo 86are not considered changes in this context. After each change you have a new 87state of the text. 88 89Note that only the changes are numbered, the text shown in the tree above has 90no identifier. They are mostly referred to by the number of the change above 91it. But sometimes by the number of one of the changes below it, especially 92when moving up in the tree, so that you know which change was just undone. 93 94============================================================================== 95*32.3* Jumping around the tree 96 97So how do you get to "one two" now? You can use this command: > 98 99 :undo 2 100 101The text is now "one two", you are below change 2. You can use the |:undo| 102command to jump to below any change in the tree. 103 104Now make another change: change "one" to "not": 105 106 one ~ 107 | 108 change 1 109 | 110 one too ~ 111 / \ 112 change 2 change 3 113 | | 114 one two me too ~ 115 | 116 change 4 117 | 118 not two ~ 119 120Now you change your mind and want to go back to "me too". Use the |g-| 121command. This moves back in time. Thus it doesn't walk the tree upwards or 122downwards, but goes to the change made before. 123 124You can repeat |g-| and you will see the text change: 125 me too ~ 126 one two ~ 127 one too ~ 128 one ~ 129 130Use |g+| to move forward in time: 131 one ~ 132 one too ~ 133 one two ~ 134 me too ~ 135 not two ~ 136 137Using |:undo| is useful if you know what change you want to jump to. |g-| and 138|g+| are useful if you don't know exactly what the change number is. 139 140You can type a count before |g-| and |g+| to repeat them. 141 142============================================================================== 143*32.4* Time travelling 144 145When you have been working on text for a while the tree grows to become big. 146Then you may want to go to the text of some minutes ago. 147 148To see what branches there are in the undo tree use this command: > 149 150 :undolist 151< number changes time ~ 152 3 2 16 seconds ago 153 4 3 5 seconds ago 154 155Here you can see the number of the leaves in each branch and when the change 156was made. Assuming we are below change 4, at "not two", you can go back ten 157seconds with this command: > 158 159 :earlier 10s 160 161Depending on how much time you took for the changes you end up at a certain 162position in the tree. The |:earlier| command argument can be "m" for minutes, 163"h" for hours and "d" for days. To go all the way back use a big number: > 164 165 :earlier 100d 166 167To travel forward in time again use the |:later| command: > 168 169 :later 1m 170 171The arguments are "s", "m" and "h", just like with |:earlier|. 172 173If you want even more details, or want to manipulate the information, you can 174use the |undotree()| function. To see what it returns: 175> 176 :echo undotree() 177< 178============================================================================== 179 180Next chapter: |usr_40.txt| Make new commands 181 182Copyright: see |manual-copyright| 183 184vim:tw=78:ts=8:noet:ft=help:norl: