Mercurial > vim
annotate runtime/doc/undo.txt @ 34676:5b25ec43f208 v9.1.0219
patch 9.1.0219: Vim9: No enum support
Commit: https://github.com/vim/vim/commit/3164cf8f12f14b725b918e3170bb0a9085af8298
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Thu Mar 28 10:36:42 2024 +0100
patch 9.1.0219: Vim9: No enum support
Problem: No enum support
Solution: Implement enums for Vim9 script
(Yegappan Lakshmanan)
closes: #14224
Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 28 Mar 2024 10:45:06 +0100 |
parents | 4635e43f2c6f |
children |
rev | line source |
---|---|
34057
4635e43f2c6f
patch 9.1.0000: Vim 9.1 release
Christian Brabandt <cb@256bit.org>
parents:
32721
diff
changeset
|
1 *undo.txt* For Vim version 9.1. Last change: 2022 Jun 02 |
7 | 2 |
3 | |
4 VIM REFERENCE MANUAL by Bram Moolenaar | |
5 | |
6 | |
7 Undo and redo *undo-redo* | |
8 | |
9 The basics are explained in section |02.5| of the user manual. | |
10 | |
11 1. Undo and redo commands |undo-commands| | |
12 2. Two ways of undo |undo-two-ways| | |
697 | 13 3. Undo blocks |undo-blocks| |
758 | 14 4. Undo branches |undo-branches| |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
15 5. Undo persistence |undo-persistence| |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
16 6. Remarks about undo |undo-remarks| |
7 | 17 |
18 ============================================================================== | |
19 1. Undo and redo commands *undo-commands* | |
20 | |
21 <Undo> or *undo* *<Undo>* *u* | |
16610 | 22 u Undo [count] changes. |
7 | 23 |
24 *:u* *:un* *:undo* | |
16610 | 25 :u[ndo] Undo one change. |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
26 *E830* |
772 | 27 :u[ndo] {N} Jump to after change number {N}. See |undo-branches| |
16553
0e473e9e70c2
patch 8.1.1280: remarks about functionality not in Vi clutters the help
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
28 for the meaning of {N}. |
772 | 29 |
7 | 30 *CTRL-R* |
16610 | 31 CTRL-R Redo [count] changes which were undone. |
7 | 32 |
33 *:red* *:redo* *redo* | |
16610 | 34 :red[o] Redo one change which was undone. |
7 | 35 |
36 *U* | |
3082 | 37 U Undo all latest changes on one line, the line where |
38 the latest change was made. |U| itself also counts as | |
39 a change, and thus |U| undoes a previous |U|. | |
7 | 40 |
41 The last changes are remembered. You can use the undo and redo commands above | |
42 to revert the text to how it was before each change. You can also apply the | |
43 changes again, getting back the text before the undo. | |
44 | |
45 The "U" command is treated by undo/redo just like any other command. Thus a | |
46 "u" command undoes a "U" command and a 'CTRL-R' command redoes it again. When | |
47 mixing "U", "u" and 'CTRL-R' you will notice that the "U" command will | |
48 restore the situation of a line to before the previous "U" command. This may | |
49 be confusing. Try it out to get used to it. | |
50 The "U" command will always mark the buffer as changed. When "U" changes the | |
51 buffer back to how it was without changes, it is still considered changed. | |
52 Use "u" to undo changes until the buffer becomes unchanged. | |
53 | |
54 ============================================================================== | |
55 2. Two ways of undo *undo-two-ways* | |
56 | |
57 How undo and redo commands work depends on the 'u' flag in 'cpoptions'. | |
5340 | 58 There is the Vim way ('u' excluded) and the Vi-compatible way ('u' included). |
7 | 59 In the Vim way, "uu" undoes two changes. In the Vi-compatible way, "uu" does |
60 nothing (undoes an undo). | |
61 | |
62 'u' excluded, the Vim way: | |
63 You can go back in time with the undo command. You can then go forward again | |
64 with the redo command. If you make a new change after the undo command, | |
65 the redo will not be possible anymore. | |
66 | |
67 'u' included, the Vi-compatible way: | |
23164 | 68 The undo command undoes the previous change, and also the previous undo |
69 command. The redo command repeats the previous undo command. It does NOT | |
70 repeat a change command, use "." for that. | |
7 | 71 |
72 Examples Vim way Vi-compatible way ~ | |
73 "uu" two times undo no-op | |
74 "u CTRL-R" no-op two times undo | |
75 | |
76 Rationale: Nvi uses the "." command instead of CTRL-R. Unfortunately, this | |
77 is not Vi compatible. For example "dwdwu." in Vi deletes two | |
78 words, in Nvi it does nothing. | |
79 | |
80 ============================================================================== | |
697 | 81 3. Undo blocks *undo-blocks* |
82 | |
83 One undo command normally undoes a typed command, no matter how many changes | |
84 that command makes. This sequence of undo-able changes forms an undo block. | |
85 Thus if the typed key(s) call a function, all the commands in the function are | |
86 undone together. | |
87 | |
88 If you want to write a function or script that doesn't create a new undoable | |
89 change but joins in with the previous change use this command: | |
90 | |
839 | 91 *:undoj* *:undojoin* *E790* |
697 | 92 :undoj[oin] Join further changes with the previous undo block. |
93 Warning: Use with care, it may prevent the user from | |
839 | 94 properly undoing changes. Don't use this after undo |
95 or redo. | |
697 | 96 |
5968 | 97 This is most useful when you need to prompt the user halfway through a change. |
98 For example in a function that calls |getchar()|. Do make sure that there was | |
99 a related change before this that you must join with. | |
697 | 100 |
101 This doesn't work by itself, because the next key press will start a new | |
102 change again. But you can do something like this: > | |
103 | |
104 :undojoin | delete | |
105 | |
23164 | 106 After this a "u" command will undo the delete command and the previous |
697 | 107 change. |
29450 | 108 *undo-break* *undo-close-block* |
109 To do the opposite, use a new undo block for the next change, in Insert mode | |
110 use CTRL-G u. This is useful if you want an insert command to be undoable in | |
2033
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1702
diff
changeset
|
111 parts. E.g., for each sentence. |i_CTRL-G_u| |
29066 | 112 |
29450 | 113 Setting the value of 'undolevels' also closes the undo block. Even when the |
32721 | 114 new value is equal to the old value. Use `g:undolevels` to explicitly read |
115 and write only the global value of 'undolevels'. In |Vim9| script: > | |
116 &g:undolevels = &g:undolevels | |
29066 | 117 In legacy script: > |
32721 | 118 let &g:undolevels = &g:undolevels |
119 | |
120 Note that the similar-looking assignment `let &undolevels=&undolevels` does not | |
121 preserve the global option value of 'undolevels' in the event that the local | |
122 option has been set to a different value. For example: > | |
123 " Start with different global and local values for 'undolevels'. | |
124 let &g:undolevels = 1000 | |
125 let &l:undolevels = 2000 | |
126 " This assignment changes the global option to 2000: | |
29066 | 127 let &undolevels = &undolevels |
2033
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1702
diff
changeset
|
128 |
697 | 129 ============================================================================== |
827 | 130 4. Undo branches *undo-branches* *undo-tree* |
758 | 131 |
793 | 132 Above we only discussed one line of undo/redo. But it is also possible to |
133 branch off. This happens when you undo a few changes and then make a new | |
134 change. The undone changes become a branch. You can go to that branch with | |
135 the following commands. | |
758 | 136 |
799 | 137 This is explained in the user manual: |usr_32.txt|. |
758 | 138 |
772 | 139 *:undol* *:undolist* |
140 :undol[ist] List the leafs in the tree of changes. Example: | |
2681 | 141 number changes when saved ~ |
142 88 88 2010/01/04 14:25:53 | |
143 108 107 08/07 12:47:51 | |
144 136 46 13:33:01 7 | |
145 166 164 3 seconds ago | |
772 | 146 |
147 The "number" column is the change number. This number | |
148 continuously increases and can be used to identify a | |
149 specific undo-able change, see |:undo|. | |
150 The "changes" column is the number of changes to this | |
151 leaf from the root of the tree. | |
2681 | 152 The "when" column is the date and time when this |
153 change was made. The four possible formats are: | |
154 N seconds ago | |
155 HH:MM:SS hour, minute, seconds | |
156 MM/DD HH:MM:SS idem, with month and day | |
157 YYYY/MM/DD HH:MM:SS idem, with year | |
2581 | 158 The "saved" column specifies, if this change was |
159 written to disk and which file write it was. This can | |
2596 | 160 be used with the |:later| and |:earlier| commands. |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
161 For more details use the |undotree()| function. |
772 | 162 |
758 | 163 *g-* |
164 g- Go to older text state. With a count repeat that many | |
16553
0e473e9e70c2
patch 8.1.1280: remarks about functionality not in Vi clutters the help
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
165 times. |
758 | 166 *:ea* *:earlier* |
167 :earlier {count} Go to older text state {count} times. | |
168 :earlier {N}s Go to older text state about {N} seconds before. | |
169 :earlier {N}m Go to older text state about {N} minutes before. | |
170 :earlier {N}h Go to older text state about {N} hours before. | |
2281
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
171 :earlier {N}d Go to older text state about {N} days before. |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
172 |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
173 :earlier {N}f Go to older text state {N} file writes before. |
2581 | 174 When changes were made since the last write |
2281
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
175 ":earlier 1f" will revert the text to the state when |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
176 it was written. Otherwise it will go to the write |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
177 before that. |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
178 When at the state of the first file write, or when |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
179 the file was not written, ":earlier 1f" will go to |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
180 before the first change. |
758 | 181 |
182 *g+* | |
183 g+ Go to newer text state. With a count repeat that many | |
16553
0e473e9e70c2
patch 8.1.1280: remarks about functionality not in Vi clutters the help
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
184 times. |
758 | 185 *:lat* *:later* |
186 :later {count} Go to newer text state {count} times. | |
187 :later {N}s Go to newer text state about {N} seconds later. | |
188 :later {N}m Go to newer text state about {N} minutes later. | |
189 :later {N}h Go to newer text state about {N} hours later. | |
2281
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
190 :later {N}d Go to newer text state about {N} days later. |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
191 |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
192 :later {N}f Go to newer text state {N} file writes later. |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
193 When at the state of the last file write, ":later 1f" |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
194 will go to the newest text state. |
758 | 195 |
772 | 196 |
758 | 197 Note that text states will become unreachable when undo information is cleared |
198 for 'undolevels'. | |
199 | |
200 Don't be surprised when moving through time shows multiple changes to take | |
201 place at a time. This happens when moving through the undo tree and then | |
202 making a new change. | |
203 | |
204 EXAMPLE | |
205 | |
206 Start with this text: | |
207 one two three ~ | |
208 | |
209 Delete the first word by pressing "x" three times: | |
210 ne two three ~ | |
211 e two three ~ | |
212 two three ~ | |
213 | |
214 Now undo that by pressing "u" three times: | |
215 e two three ~ | |
216 ne two three ~ | |
217 one two three ~ | |
218 | |
219 Delete the second word by pressing "x" three times: | |
220 one wo three ~ | |
221 one o three ~ | |
222 one three ~ | |
223 | |
224 Now undo that by using "g-" three times: | |
225 one o three ~ | |
226 one wo three ~ | |
227 two three ~ | |
228 | |
229 You are now back in the first undo branch, after deleting "one". Repeating | |
230 "g-" will now bring you back to the original text: | |
231 e two three ~ | |
232 ne two three ~ | |
233 one two three ~ | |
234 | |
235 Jump to the last change with ":later 1h": | |
236 one three ~ | |
237 | |
238 And back to the start again with ":earlier 1h": | |
239 one two three ~ | |
240 | |
241 | |
242 Note that using "u" and CTRL-R will not get you to all possible text states | |
243 while repeating "g-" and "g+" does. | |
244 | |
245 ============================================================================== | |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
246 5. Undo persistence *undo-persistence* *persistent-undo* |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
247 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
248 When unloading a buffer Vim normally destroys the tree of undos created for |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
249 that buffer. By setting the 'undofile' option, Vim will automatically save |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
250 your undo history when you write a file and restore undo history when you edit |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
251 the file again. |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
252 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
253 The 'undofile' option is checked after writing a file, before the BufWritePost |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
254 autocommands. If you want to control what files to write undo information |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
255 for, you can use a BufWritePre autocommand: > |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
256 au BufWritePre /tmp/* setlocal noundofile |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
257 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
258 Vim saves undo trees in a separate undo file, one for each edited file, using |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
259 a simple scheme that maps filesystem paths directly to undo files. Vim will |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
260 detect if an undo file is no longer synchronized with the file it was written |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
261 for (with a hash of the file contents) and ignore it when the file was changed |
2625 | 262 after the undo file was written, to prevent corruption. An undo file is also |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
5340
diff
changeset
|
263 ignored if its owner differs from the owner of the edited file, except when |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
5340
diff
changeset
|
264 the owner of the undo file is the current user. Set 'verbose' to get a |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
5340
diff
changeset
|
265 message about that when opening a file. |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
266 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
267 Undo files are normally saved in the same directory as the file. This can be |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
268 changed with the 'undodir' option. |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
269 |
29193 | 270 When the file is encrypted, the text in the undo file is also encrypted. The |
2239
732cb7b31956
Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents:
2238
diff
changeset
|
271 same key and method is used. |encryption| |
732cb7b31956
Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents:
2238
diff
changeset
|
272 |
15512 | 273 Note that text properties are not stored in the undo file. You can restore |
274 text properties so long as a buffer is loaded, but you cannot restore them | |
275 from an undo file. Rationale: It would require the associated text property | |
276 types to be defined in exactly the same was as before, which cannot be | |
277 guaranteed. | |
278 | |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
279 You can also save and restore undo histories by using ":wundo" and ":rundo" |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
280 respectively: |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
281 *:wundo* *:rundo* |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
282 :wundo[!] {file} |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
283 Write undo history to {file}. |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
284 When {file} exists and it does not look like an undo file |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
285 (the magic number at the start of the file is wrong), then |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
286 this fails, unless the ! was added. |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
287 If it exists and does look like an undo file it is |
18831 | 288 overwritten. If there is no undo-history, nothing will be |
3312 | 289 written. |
290 Implementation detail: Overwriting happens by first deleting | |
291 the existing file and then creating a new file with the same | |
292 name. So it is not possible to overwrite an existing undofile | |
293 in a write-protected directory. | |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
294 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
295 :rundo {file} Read undo history from {file}. |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
296 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
297 You can use these in autocommands to explicitly specify the name of the |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
298 history file. E.g.: > |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
299 |
2236
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
300 au BufReadPost * call ReadUndo() |
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
301 au BufWritePost * call WriteUndo() |
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
302 func ReadUndo() |
27903 | 303 if filereadable(expand('%:h') .. '/UNDO/' .. expand('%:t')) |
2236
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
304 rundo %:h/UNDO/%:t |
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
305 endif |
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
306 endfunc |
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
307 func WriteUndo() |
27903 | 308 let dirname = expand('%:h') .. '/UNDO' |
2236
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
309 if !isdirectory(dirname) |
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
310 call mkdir(dirname) |
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
311 endif |
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
312 wundo %:h/UNDO/%:t |
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
313 endfunc |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
314 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
315 You should keep 'undofile' off, otherwise you end up with two undo files for |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
316 every write. |
2236
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
317 |
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
318 You can use the |undofile()| function to find out the file name that Vim would |
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
319 use. |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
320 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
321 Note that while reading/writing files and 'undofile' is set most errors will |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
322 be silent, unless 'verbose' is set. With :wundo and :rundo you will get more |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
323 error messages, e.g., when the file cannot be read or written. |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
324 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
325 NOTE: undo files are never deleted by Vim. You need to delete them yourself. |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
326 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
327 Reading an existing undo file may fail for several reasons: |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
328 *E822* It cannot be opened, because the file permissions don't allow it. |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
329 *E823* The magic number at the start of the file doesn't match. This usually |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
330 means it is not an undo file. |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
331 *E824* The version number of the undo file indicates that it's written by a |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
332 newer version of Vim. You need that newer version to open it. Don't |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
333 write the buffer if you want to keep the undo info in the file. |
2215
cccb71c2c5c1
Fix uninit memory read in undo code. Fix uint32_t in proto file.
Bram Moolenaar <bram@vim.org>
parents:
2214
diff
changeset
|
334 "File contents changed, cannot use undo info" |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
335 The file text differs from when the undo file was written. This means |
2215
cccb71c2c5c1
Fix uninit memory read in undo code. Fix uint32_t in proto file.
Bram Moolenaar <bram@vim.org>
parents:
2214
diff
changeset
|
336 the undo file cannot be used, it would corrupt the text. This also |
cccb71c2c5c1
Fix uninit memory read in undo code. Fix uint32_t in proto file.
Bram Moolenaar <bram@vim.org>
parents:
2214
diff
changeset
|
337 happens when 'encoding' differs from when the undo file was written. |
2231
aa6412cab544
Various improvements to undo file code to make it more robust.
Bram Moolenaar <bram@vim.org>
parents:
2223
diff
changeset
|
338 *E825* The undo file does not contain valid contents and cannot be used. |
2251
646d34788036
Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents:
2249
diff
changeset
|
339 *E826* The undo file is encrypted but decryption failed. |
646d34788036
Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents:
2249
diff
changeset
|
340 *E827* The undo file is encrypted but this version of Vim does not support |
646d34788036
Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents:
2249
diff
changeset
|
341 encryption. Open the file with another Vim. |
646d34788036
Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents:
2249
diff
changeset
|
342 *E832* The undo file is encrypted but 'key' is not set, the text file is not |
646d34788036
Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents:
2249
diff
changeset
|
343 encrypted. This would happen if the text file was written by Vim |
646d34788036
Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents:
2249
diff
changeset
|
344 encrypted at first, and later overwritten by not encrypted text. |
646d34788036
Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents:
2249
diff
changeset
|
345 You probably want to delete this undo file. |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
346 "Not reading undo file, owner differs" |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
347 The undo file is owned by someone else than the owner of the text |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
348 file. For safety the undo file is not used. |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
349 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
350 Writing an undo file may fail for these reasons: |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
351 *E828* The file to be written cannot be created. Perhaps you do not have |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
352 write permissions in the directory. |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
353 "Cannot write undo file in any directory in 'undodir'" |
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
354 None of the directories in 'undodir' can be used. |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
355 "Will not overwrite with undo file, cannot read" |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
356 A file exists with the name of the undo file to be written, but it |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
357 cannot be read. You may want to delete this file or rename it. |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
358 "Will not overwrite, this is not an undo file" |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
359 A file exists with the name of the undo file to be written, but it |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
360 does not start with the right magic number. You may want to delete |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
361 this file or rename it. |
2581 | 362 "Skipping undo file write, nothing to undo" |
363 There is no undo information to be written, nothing has been changed | |
2238
3d0a7beb0d75
Made reading/writing undo info a bit more robust.
Bram Moolenaar <bram@vim.org>
parents:
2236
diff
changeset
|
364 or 'undolevels' is negative. |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
365 *E829* An error occurred while writing the undo file. You may want to try |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
366 again. |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
367 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
368 ============================================================================== |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
369 6. Remarks about undo *undo-remarks* |
7 | 370 |
371 The number of changes that are remembered is set with the 'undolevels' option. | |
372 If it is zero, the Vi-compatible way is always used. If it is negative no | |
373 undo is possible. Use this if you are running out of memory. | |
374 | |
2249
6d3d35ff2c2b
Use full path in undofile(). Updated docs.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
375 *clear-undo* |
6d3d35ff2c2b
Use full path in undofile(). Updated docs.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
376 When you set 'undolevels' to -1 the undo information is not immediately |
6d3d35ff2c2b
Use full path in undofile(). Updated docs.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
377 cleared, this happens at the next change. To force clearing the undo |
6d3d35ff2c2b
Use full path in undofile(). Updated docs.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
378 information you can use these commands: > |
32721 | 379 :let old_undolevels = &l:undolevels |
380 :setlocal undolevels=-1 | |
2249
6d3d35ff2c2b
Use full path in undofile(). Updated docs.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
381 :exe "normal a \<BS>\<Esc>" |
32721 | 382 :let &l:undolevels = old_undolevels |
2249
6d3d35ff2c2b
Use full path in undofile(). Updated docs.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
383 :unlet old_undolevels |
6d3d35ff2c2b
Use full path in undofile(). Updated docs.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
384 |
32721 | 385 Note use of `&l:undolevels` to explicitly read the local value of 'undolevels' |
386 and the use of `:setlocal` to change only the local option (which takes | |
387 precedence over the corresponding global option value). Saving the option value | |
388 via the use of `&undolevels` is unpredictable; it reads either the local value | |
389 (if one has been set) or the global value (otherwise). Also, if a local value | |
390 has been set, changing the option via `:set undolevels` will change both the | |
391 global and local values, requiring extra work to save and restore both values. | |
392 | |
7 | 393 Marks for the buffer ('a to 'z) are also saved and restored, together with the |
16553
0e473e9e70c2
patch 8.1.1280: remarks about functionality not in Vi clutters the help
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
394 text. |
7 | 395 |
396 When all changes have been undone, the buffer is not considered to be changed. | |
16553
0e473e9e70c2
patch 8.1.1280: remarks about functionality not in Vi clutters the help
Bram Moolenaar <Bram@vim.org>
parents:
15512
diff
changeset
|
397 It is then possible to exit Vim with ":q" instead of ":q!". Note |
7 | 398 that this is relative to the last write of the file. Typing "u" after ":w" |
399 actually changes the buffer, compared to what was written, so the buffer is | |
400 considered changed then. | |
401 | |
402 When manual |folding| is being used, the folds are not saved and restored. | |
403 Only changes completely within a fold will keep the fold as it was, because | |
404 the first and last line of the fold don't change. | |
405 | |
406 The numbered registers can also be used for undoing deletes. Each time you | |
407 delete text, it is put into register "1. The contents of register "1 are | |
408 shifted to "2, etc. The contents of register "9 are lost. You can now get | |
409 back the most recent deleted text with the put command: '"1P'. (also, if the | |
410 deleted text was the result of the last delete or copy operation, 'P' or 'p' | |
411 also works as this puts the contents of the unnamed register). You can get | |
412 back the text of three deletes ago with '"3P'. | |
413 | |
414 *redo-register* | |
415 If you want to get back more than one part of deleted text, you can use a | |
416 special feature of the repeat command ".". It will increase the number of the | |
22723 | 417 register used. So if you first do '"1P', the following "." will result in a |
7 | 418 '"2P'. Repeating this will result in all numbered registers being inserted. |
419 | |
420 Example: If you deleted text with 'dd....' it can be restored with | |
421 '"1P....'. | |
422 | |
423 If you don't know in which register the deleted text is, you can use the | |
424 :display command. An alternative is to try the first register with '"1P', and | |
425 if it is not what you want do 'u.'. This will remove the contents of the | |
426 first put, and repeat the put command for the second register. Repeat the | |
427 'u.' until you got what you want. | |
428 | |
14519 | 429 vim:tw=78:ts=8:noet:ft=help:norl: |