comparison runtime/doc/undo.txt @ 2214:f8222d1f9a73 vim73

Included patch for persistent undo. Lots of changes and added test.
author Bram Moolenaar <bram@vim.org>
date Sun, 23 May 2010 23:34:36 +0200
parents 7c8c7c95a865
children cccb71c2c5c1
comparison
equal deleted inserted replaced
2213:0e0e99d1092e 2214:f8222d1f9a73
10 10
11 1. Undo and redo commands |undo-commands| 11 1. Undo and redo commands |undo-commands|
12 2. Two ways of undo |undo-two-ways| 12 2. Two ways of undo |undo-two-ways|
13 3. Undo blocks |undo-blocks| 13 3. Undo blocks |undo-blocks|
14 4. Undo branches |undo-branches| 14 4. Undo branches |undo-branches|
15 5. Remarks about undo |undo-remarks| 15 5. Undo persistence |undo-persistence|
16 6. Remarks about undo |undo-remarks|
16 17
17 ============================================================================== 18 ==============================================================================
18 1. Undo and redo commands *undo-commands* 19 1. Undo and redo commands *undo-commands*
19 20
20 <Undo> or *undo* *<Undo>* *u* 21 <Undo> or *undo* *<Undo>* *u*
21 u Undo [count] changes. {Vi: only one level} 22 u Undo [count] changes. {Vi: only one level}
22 23
23 *:u* *:un* *:undo* 24 *:u* *:un* *:undo*
24 :u[ndo] Undo one change. {Vi: only one level} 25 :u[ndo] Undo one change. {Vi: only one level}
25 26 *E830*
26 :u[ndo] {N} Jump to after change number {N}. See |undo-branches| 27 :u[ndo] {N} Jump to after change number {N}. See |undo-branches|
27 for the meaning of {N}. {not in Vi} 28 for the meaning of {N}. {not in Vi}
28 29
29 *CTRL-R* 30 *CTRL-R*
30 CTRL-R Redo [count] changes which were undone. {Vi: redraw 31 CTRL-R Redo [count] changes which were undone. {Vi: redraw
107 change. 108 change.
108 109
109 To do the opposite, break a change into two undo blocks, in Insert mode use 110 To do the opposite, break a change into two undo blocks, in Insert mode use
110 CTRL-G u. This is useful if you want an insert command to be undoable in 111 CTRL-G u. This is useful if you want an insert command to be undoable in
111 parts. E.g., for each sentence. |i_CTRL-G_u| 112 parts. E.g., for each sentence. |i_CTRL-G_u|
113 Setting the value of 'undolevels' also breaks undo. Even when the new value
114 is equal to the old value.
112 115
113 ============================================================================== 116 ==============================================================================
114 4. Undo branches *undo-branches* *undo-tree* 117 4. Undo branches *undo-branches* *undo-tree*
115 118
116 Above we only discussed one line of undo/redo. But it is also possible to 119 Above we only discussed one line of undo/redo. But it is also possible to
199 202
200 Note that using "u" and CTRL-R will not get you to all possible text states 203 Note that using "u" and CTRL-R will not get you to all possible text states
201 while repeating "g-" and "g+" does. 204 while repeating "g-" and "g+" does.
202 205
203 ============================================================================== 206 ==============================================================================
204 5. Remarks about undo *undo-remarks* 207 5. Undo persistence *undo-persistence* *persistent-undo*
208
209 When unloading a buffer Vim normally destroys the tree of undos created for
210 that buffer. By setting the 'undofile' option, Vim will automatically save
211 your undo history when you write a file and restore undo history when you edit
212 the file again.
213
214 The 'undofile' option is checked after writing a file, before the BufWritePost
215 autocommands. If you want to control what files to write undo information
216 for, you can use a BufWritePre autocommand: >
217 au BufWritePre /tmp/* setlocal noundofile
218
219 Vim saves undo trees in a separate undo file, one for each edited file, using
220 a simple scheme that maps filesystem paths directly to undo files. Vim will
221 detect if an undo file is no longer synchronized with the file it was written
222 for (with a hash of the file contents) and ignore it when the file was changed
223 after the undo file was written, to prevent corruption.
224
225 Undo files are normally saved in the same directory as the file. This can be
226 changed with the 'undodir' option.
227
228 You can also save and restore undo histories by using ":wundo" and ":rundo"
229 respectively:
230 *:wundo* *:rundo*
231 :wundo[!] {file}
232 Write undo history to {file}.
233 When {file} exists and it does not look like an undo file
234 (the magic number at the start of the file is wrong), then
235 this fails, unless the ! was added.
236 If it exists and does look like an undo file it is
237 overwritten.
238 {not in Vi}
239
240 :rundo {file} Read undo history from {file}.
241 {not in Vi}
242
243 You can use these in autocommands to explicitly specify the name of the
244 history file. E.g.: >
245
246 au BufReadPost * rundo %:h/UNDO/%:t
247 au BufWritePost * wundo %:h/UNDO/%:t
248
249 You should keep 'undofile' off, otherwise you end up with two undo files for
250 every write.
251 Note: I did not verify this always works!
252
253 Note that while reading/writing files and 'undofile' is set most errors will
254 be silent, unless 'verbose' is set. With :wundo and :rundo you will get more
255 error messages, e.g., when the file cannot be read or written.
256
257 NOTE: undo files are never deleted by Vim. You need to delete them yourself.
258
259 Reading an existing undo file may fail for several reasons:
260 *E822* It cannot be opened, because the file permissions don't allow it.
261 *E823* The magic number at the start of the file doesn't match. This usually
262 means it is not an undo file.
263 *E824* The version number of the undo file indicates that it's written by a
264 newer version of Vim. You need that newer version to open it. Don't
265 write the buffer if you want to keep the undo info in the file.
266 "Undo file contents changed"
267 The file text differs from when the undo file was written. This means
268 the undo file cannot be used, it would corrupt the text.
269 *E825* *E826* The undo file does not contain valid contents and cannot be
270 used.
271 *E827* The magic number at the end of the file was not found. This usually
272 means the file was truncated.
273
274 Writing an undo file may fail for these reasons:
275 *E828* The file to be written cannot be created. Perhaps you do not have
276 write permissions in the directory.
277 "Will not overwrite with undo file, cannot read"
278 A file exists with the name of the undo file to be written, but it
279 cannot be read. You may want to delete this file or rename it.
280 "Will not overwrite, this is not an undo file"
281 A file exists with the name of the undo file to be written, but it
282 does not start with the right magic number. You may want to delete
283 this file or rename it.
284 *E829* An error occurred while writing the undo file. You may want to try
285 again.
286
287 ==============================================================================
288 6. Remarks about undo *undo-remarks*
205 289
206 The number of changes that are remembered is set with the 'undolevels' option. 290 The number of changes that are remembered is set with the 'undolevels' option.
207 If it is zero, the Vi-compatible way is always used. If it is negative no 291 If it is zero, the Vi-compatible way is always used. If it is negative no
208 undo is possible. Use this if you are running out of memory. 292 undo is possible. Use this if you are running out of memory.
209 293