Mercurial > vim
annotate runtime/doc/undo.txt @ 12269:d2373927d76d v8.0.1014
patch 8.0.1014: old compiler doesn't know uint32_t
commit https://github.com/vim/vim/commit/b47a2597e64b4c4f728433ae005cf6ff1d0dd5c1
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Aug 30 13:22:28 2017 +0200
patch 8.0.1014: old compiler doesn't know uint32_t
Problem: Old compiler doesn't know uint32_t. Warning for using NULL instead
of NUL.
Solution: Use UINT32_T. Use NUL instead of NULL.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Wed, 30 Aug 2017 13:30:04 +0200 |
parents | 9f48eab77d62 |
children | 1174611ad715 |
rev | line source |
---|---|
10198
9f48eab77d62
commit https://github.com/vim/vim/commit/bb76f24af2010943387ce696a7092175b4ecccf2
Christian Brabandt <cb@256bit.org>
parents:
5968
diff
changeset
|
1 *undo.txt* For Vim version 8.0. Last change: 2014 May 24 |
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* | |
22 u Undo [count] changes. {Vi: only one level} | |
23 | |
24 *:u* *:un* *:undo* | |
25 :u[ndo] Undo one change. {Vi: only one level} | |
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| |
28 for the meaning of {N}. {not in Vi} | |
29 | |
7 | 30 *CTRL-R* |
31 CTRL-R Redo [count] changes which were undone. {Vi: redraw | |
32 screen} | |
33 | |
34 *:red* *:redo* *redo* | |
35 :red[o] Redo one change which was undone. {Vi: no redo} | |
36 | |
37 *U* | |
3082 | 38 U Undo all latest changes on one line, the line where |
39 the latest change was made. |U| itself also counts as | |
40 a change, and thus |U| undoes a previous |U|. | |
41 {Vi: while not moved off of the last modified line} | |
7 | 42 |
43 The last changes are remembered. You can use the undo and redo commands above | |
44 to revert the text to how it was before each change. You can also apply the | |
45 changes again, getting back the text before the undo. | |
46 | |
47 The "U" command is treated by undo/redo just like any other command. Thus a | |
48 "u" command undoes a "U" command and a 'CTRL-R' command redoes it again. When | |
49 mixing "U", "u" and 'CTRL-R' you will notice that the "U" command will | |
50 restore the situation of a line to before the previous "U" command. This may | |
51 be confusing. Try it out to get used to it. | |
52 The "U" command will always mark the buffer as changed. When "U" changes the | |
53 buffer back to how it was without changes, it is still considered changed. | |
54 Use "u" to undo changes until the buffer becomes unchanged. | |
55 | |
56 ============================================================================== | |
57 2. Two ways of undo *undo-two-ways* | |
58 | |
59 How undo and redo commands work depends on the 'u' flag in 'cpoptions'. | |
5340 | 60 There is the Vim way ('u' excluded) and the Vi-compatible way ('u' included). |
7 | 61 In the Vim way, "uu" undoes two changes. In the Vi-compatible way, "uu" does |
62 nothing (undoes an undo). | |
63 | |
64 'u' excluded, the Vim way: | |
65 You can go back in time with the undo command. You can then go forward again | |
66 with the redo command. If you make a new change after the undo command, | |
67 the redo will not be possible anymore. | |
68 | |
69 'u' included, the Vi-compatible way: | |
70 The undo command undoes the previous change, and also the previous undo command. | |
71 The redo command repeats the previous undo command. It does NOT repeat a | |
72 change command, use "." for that. | |
73 | |
74 Examples Vim way Vi-compatible way ~ | |
75 "uu" two times undo no-op | |
76 "u CTRL-R" no-op two times undo | |
77 | |
78 Rationale: Nvi uses the "." command instead of CTRL-R. Unfortunately, this | |
79 is not Vi compatible. For example "dwdwu." in Vi deletes two | |
80 words, in Nvi it does nothing. | |
81 | |
82 ============================================================================== | |
697 | 83 3. Undo blocks *undo-blocks* |
84 | |
85 One undo command normally undoes a typed command, no matter how many changes | |
86 that command makes. This sequence of undo-able changes forms an undo block. | |
87 Thus if the typed key(s) call a function, all the commands in the function are | |
88 undone together. | |
89 | |
90 If you want to write a function or script that doesn't create a new undoable | |
91 change but joins in with the previous change use this command: | |
92 | |
839 | 93 *:undoj* *:undojoin* *E790* |
697 | 94 :undoj[oin] Join further changes with the previous undo block. |
95 Warning: Use with care, it may prevent the user from | |
839 | 96 properly undoing changes. Don't use this after undo |
97 or redo. | |
697 | 98 {not in Vi} |
99 | |
5968 | 100 This is most useful when you need to prompt the user halfway through a change. |
101 For example in a function that calls |getchar()|. Do make sure that there was | |
102 a related change before this that you must join with. | |
697 | 103 |
104 This doesn't work by itself, because the next key press will start a new | |
105 change again. But you can do something like this: > | |
106 | |
107 :undojoin | delete | |
108 | |
109 After this an "u" command will undo the delete command and the previous | |
110 change. | |
111 | |
2033
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1702
diff
changeset
|
112 To do the opposite, break a change into two undo blocks, in Insert mode use |
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1702
diff
changeset
|
113 CTRL-G u. This is useful if you want an insert command to be undoable in |
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1702
diff
changeset
|
114 parts. E.g., for each sentence. |i_CTRL-G_u| |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
115 Setting the value of 'undolevels' also breaks undo. Even when the new value |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
116 is equal to the old value. |
2033
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1702
diff
changeset
|
117 |
697 | 118 ============================================================================== |
827 | 119 4. Undo branches *undo-branches* *undo-tree* |
758 | 120 |
793 | 121 Above we only discussed one line of undo/redo. But it is also possible to |
122 branch off. This happens when you undo a few changes and then make a new | |
123 change. The undone changes become a branch. You can go to that branch with | |
124 the following commands. | |
758 | 125 |
799 | 126 This is explained in the user manual: |usr_32.txt|. |
758 | 127 |
772 | 128 *:undol* *:undolist* |
129 :undol[ist] List the leafs in the tree of changes. Example: | |
2681 | 130 number changes when saved ~ |
131 88 88 2010/01/04 14:25:53 | |
132 108 107 08/07 12:47:51 | |
133 136 46 13:33:01 7 | |
134 166 164 3 seconds ago | |
772 | 135 |
136 The "number" column is the change number. This number | |
137 continuously increases and can be used to identify a | |
138 specific undo-able change, see |:undo|. | |
139 The "changes" column is the number of changes to this | |
140 leaf from the root of the tree. | |
2681 | 141 The "when" column is the date and time when this |
142 change was made. The four possible formats are: | |
143 N seconds ago | |
144 HH:MM:SS hour, minute, seconds | |
145 MM/DD HH:MM:SS idem, with month and day | |
146 YYYY/MM/DD HH:MM:SS idem, with year | |
2581 | 147 The "saved" column specifies, if this change was |
148 written to disk and which file write it was. This can | |
2596 | 149 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
|
150 For more details use the |undotree()| function. |
772 | 151 |
758 | 152 *g-* |
153 g- Go to older text state. With a count repeat that many | |
154 times. {not in Vi} | |
155 *:ea* *:earlier* | |
156 :earlier {count} Go to older text state {count} times. | |
157 :earlier {N}s Go to older text state about {N} seconds before. | |
158 :earlier {N}m Go to older text state about {N} minutes before. | |
159 :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
|
160 :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
|
161 |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
162 :earlier {N}f Go to older text state {N} file writes before. |
2581 | 163 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
|
164 ":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
|
165 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
|
166 before that. |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
167 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
|
168 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
|
169 before the first change. |
758 | 170 |
171 *g+* | |
172 g+ Go to newer text state. With a count repeat that many | |
173 times. {not in Vi} | |
174 *:lat* *:later* | |
175 :later {count} Go to newer text state {count} times. | |
176 :later {N}s Go to newer text state about {N} seconds later. | |
177 :later {N}m Go to newer text state about {N} minutes later. | |
178 :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
|
179 :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
|
180 |
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
181 :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
|
182 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
|
183 will go to the newest text state. |
758 | 184 |
772 | 185 |
758 | 186 Note that text states will become unreachable when undo information is cleared |
187 for 'undolevels'. | |
188 | |
189 Don't be surprised when moving through time shows multiple changes to take | |
190 place at a time. This happens when moving through the undo tree and then | |
191 making a new change. | |
192 | |
193 EXAMPLE | |
194 | |
195 Start with this text: | |
196 one two three ~ | |
197 | |
198 Delete the first word by pressing "x" three times: | |
199 ne two three ~ | |
200 e two three ~ | |
201 two three ~ | |
202 | |
203 Now undo that by pressing "u" three times: | |
204 e two three ~ | |
205 ne two three ~ | |
206 one two three ~ | |
207 | |
208 Delete the second word by pressing "x" three times: | |
209 one wo three ~ | |
210 one o three ~ | |
211 one three ~ | |
212 | |
213 Now undo that by using "g-" three times: | |
214 one o three ~ | |
215 one wo three ~ | |
216 two three ~ | |
217 | |
218 You are now back in the first undo branch, after deleting "one". Repeating | |
219 "g-" will now bring you back to the original text: | |
220 e two three ~ | |
221 ne two three ~ | |
222 one two three ~ | |
223 | |
224 Jump to the last change with ":later 1h": | |
225 one three ~ | |
226 | |
227 And back to the start again with ":earlier 1h": | |
228 one two three ~ | |
229 | |
230 | |
231 Note that using "u" and CTRL-R will not get you to all possible text states | |
232 while repeating "g-" and "g+" does. | |
233 | |
234 ============================================================================== | |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
235 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
|
236 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
237 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
|
238 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
|
239 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
|
240 the file again. |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
241 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
242 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
|
243 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
|
244 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
|
245 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
|
246 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
247 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
|
248 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
|
249 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
|
250 for (with a hash of the file contents) and ignore it when the file was changed |
2625 | 251 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
|
252 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
|
253 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
|
254 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
|
255 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
256 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
|
257 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
|
258 |
2239
732cb7b31956
Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents:
2238
diff
changeset
|
259 When the file is encrypted, the text in the undo file is also crypted. The |
732cb7b31956
Crypt the text in the undo file if the file itself is crypted.
Bram Moolenaar <bram@vim.org>
parents:
2238
diff
changeset
|
260 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
|
261 |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
262 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
|
263 respectively: |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
264 *:wundo* *:rundo* |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
265 :wundo[!] {file} |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
266 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
|
267 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
|
268 (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
|
269 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
|
270 If it exists and does look like an undo file it is |
3312 | 271 overwritten. If there is no undo-history, nothing will be |
272 written. | |
273 Implementation detail: Overwriting happens by first deleting | |
274 the existing file and then creating a new file with the same | |
275 name. So it is not possible to overwrite an existing undofile | |
276 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
|
277 {not in Vi} |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
278 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
279 :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
|
280 {not in Vi} |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
281 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
282 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
|
283 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
|
284 |
2236
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
285 au BufReadPost * call ReadUndo() |
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
286 au BufWritePost * call WriteUndo() |
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
287 func ReadUndo() |
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
288 if filereadable(expand('%:h'). '/UNDO/' . expand('%:t')) |
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
289 rundo %:h/UNDO/%:t |
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
290 endif |
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
291 endfunc |
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
292 func WriteUndo() |
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
293 let dirname = expand('%:h') . '/UNDO' |
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
294 if !isdirectory(dirname) |
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
295 call mkdir(dirname) |
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
296 endif |
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
297 wundo %:h/UNDO/%:t |
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
298 endfunc |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
299 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
300 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
|
301 every write. |
2236
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
302 |
dc2e5ec0500d
Added the undofile() function. Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2231
diff
changeset
|
303 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
|
304 use. |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
305 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
306 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
|
307 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
|
308 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
|
309 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
310 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
|
311 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
312 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
|
313 *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
|
314 *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
|
315 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
|
316 *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
|
317 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
|
318 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
|
319 "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
|
320 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
|
321 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
|
322 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
|
323 *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
|
324 *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
|
325 *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
|
326 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
|
327 *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
|
328 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
|
329 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
|
330 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
|
331 "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
|
332 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
|
333 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
|
334 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
335 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
|
336 *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
|
337 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
|
338 "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
|
339 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
|
340 "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
|
341 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
|
342 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
|
343 "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
|
344 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
|
345 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
|
346 this file or rename it. |
2581 | 347 "Skipping undo file write, nothing to undo" |
348 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
|
349 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
|
350 *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
|
351 again. |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
352 |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
353 ============================================================================== |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
354 6. Remarks about undo *undo-remarks* |
7 | 355 |
356 The number of changes that are remembered is set with the 'undolevels' option. | |
357 If it is zero, the Vi-compatible way is always used. If it is negative no | |
358 undo is possible. Use this if you are running out of memory. | |
359 | |
2249
6d3d35ff2c2b
Use full path in undofile(). Updated docs.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
360 *clear-undo* |
6d3d35ff2c2b
Use full path in undofile(). Updated docs.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
361 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
|
362 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
|
363 information you can use these commands: > |
6d3d35ff2c2b
Use full path in undofile(). Updated docs.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
364 :let old_undolevels = &undolevels |
6d3d35ff2c2b
Use full path in undofile(). Updated docs.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
365 :set undolevels=-1 |
6d3d35ff2c2b
Use full path in undofile(). Updated docs.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
366 :exe "normal a \<BS>\<Esc>" |
6d3d35ff2c2b
Use full path in undofile(). Updated docs.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
367 :let &undolevels = old_undolevels |
6d3d35ff2c2b
Use full path in undofile(). Updated docs.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
368 :unlet old_undolevels |
6d3d35ff2c2b
Use full path in undofile(). Updated docs.
Bram Moolenaar <bram@vim.org>
parents:
2239
diff
changeset
|
369 |
7 | 370 Marks for the buffer ('a to 'z) are also saved and restored, together with the |
371 text. {Vi does this a little bit different} | |
372 | |
373 When all changes have been undone, the buffer is not considered to be changed. | |
374 It is then possible to exit Vim with ":q" instead of ":q!" {not in Vi}. Note | |
375 that this is relative to the last write of the file. Typing "u" after ":w" | |
376 actually changes the buffer, compared to what was written, so the buffer is | |
377 considered changed then. | |
378 | |
379 When manual |folding| is being used, the folds are not saved and restored. | |
380 Only changes completely within a fold will keep the fold as it was, because | |
381 the first and last line of the fold don't change. | |
382 | |
383 The numbered registers can also be used for undoing deletes. Each time you | |
384 delete text, it is put into register "1. The contents of register "1 are | |
385 shifted to "2, etc. The contents of register "9 are lost. You can now get | |
386 back the most recent deleted text with the put command: '"1P'. (also, if the | |
387 deleted text was the result of the last delete or copy operation, 'P' or 'p' | |
388 also works as this puts the contents of the unnamed register). You can get | |
389 back the text of three deletes ago with '"3P'. | |
390 | |
391 *redo-register* | |
392 If you want to get back more than one part of deleted text, you can use a | |
393 special feature of the repeat command ".". It will increase the number of the | |
394 register used. So if you first do ""1P", the following "." will result in a | |
395 '"2P'. Repeating this will result in all numbered registers being inserted. | |
396 | |
397 Example: If you deleted text with 'dd....' it can be restored with | |
398 '"1P....'. | |
399 | |
400 If you don't know in which register the deleted text is, you can use the | |
401 :display command. An alternative is to try the first register with '"1P', and | |
402 if it is not what you want do 'u.'. This will remove the contents of the | |
403 first put, and repeat the put command for the second register. Repeat the | |
404 'u.' until you got what you want. | |
405 | |
406 vim:tw=78:ts=8:ft=help:norl: |