Mercurial > vim
annotate runtime/doc/recover.txt @ 15030:3a33febf426b
Added tag v8.1.0526 for changeset 588a5fafbb61fc795bcf49a0ebcdf77e2a5fc550
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 12 Nov 2018 22:00:07 +0100 |
parents | 40ef13331e02 |
children | 1eaf34420bb3 |
rev | line source |
---|---|
13963 | 1 *recover.txt* For Vim version 8.1. Last change: 2014 Mar 27 |
7 | 2 |
3 | |
4 VIM REFERENCE MANUAL by Bram Moolenaar | |
5 | |
6 | |
7 Recovery after a crash *crash-recovery* | |
8 | |
9 You have spent several hours typing in that text that has to be finished | |
10 next morning, and then disaster strikes: Your computer crashes. | |
11 | |
12 DON'T PANIC! | |
13 | |
14 You can recover most of your changes from the files that Vim uses to store | |
15 the contents of the file. Mostly you can recover your work with one command: | |
16 vim -r filename | |
17 | |
18 1. The swap file |swap-file| | |
19 2. Recovery |recovery| | |
20 | |
21 ============================================================================== | |
22 1. The swap file *swap-file* | |
23 | |
24 Vim stores the things you changed in a swap file. Using the original file | |
25 you started from plus the swap file you can mostly recover your work. | |
26 | |
27 You can see the name of the current swap file being used with the command: | |
28 | |
29 :sw[apname] *:sw* *:swapname* | |
30 | |
14864 | 31 Or you can use the |swapname()| function, which also allows for seeing the |
32 swap file name of other buffers. | |
33 | |
7 | 34 The name of the swap file is normally the same as the file you are editing, |
35 with the extension ".swp". | |
36 - On Unix, a '.' is prepended to swap file names in the same directory as the | |
37 edited file. This avoids that the swap file shows up in a directory | |
38 listing. | |
39 - On MS-DOS machines and when the 'shortname' option is on, any '.' in the | |
40 original file name is replaced with '_'. | |
41 - If this file already exists (e.g., when you are recovering from a crash) a | |
42 warning is given and another extension is used, ".swo", ".swn", etc. | |
43 - An existing file will never be overwritten. | |
44 - The swap file is deleted as soon as Vim stops editing the file. | |
45 | |
46 Technical: The replacement of '.' with '_' is done to avoid problems with | |
47 MS-DOS compatible filesystems (e.g., crossdos, multidos). If Vim | |
48 is able to detect that the file is on an MS-DOS-like filesystem, a | |
49 flag is set that has the same effect as the 'shortname' option. | |
50 This flag is reset when you start editing another file. | |
51 *E326* | |
52 If the ".swp" file name already exists, the last character is | |
53 decremented until there is no file with that name or ".saa" is | |
54 reached. In the last case, no swap file is created. | |
55 | |
56 By setting the 'directory' option you can place the swap file in another place | |
57 than where the edited file is. | |
58 Advantages: | |
59 - You will not pollute the directories with ".swp" files. | |
60 - When the 'directory' is on another partition, reduce the risk of damaging | |
61 the file system where the file is (in a crash). | |
62 Disadvantages: | |
63 - You can get name collisions from files with the same name but in different | |
64 directories (although Vim tries to avoid that by comparing the path name). | |
65 This will result in bogus ATTENTION warning messages. | |
66 - When you use your home directory, and somebody else tries to edit the same | |
9 | 67 file, he will not see your swap file and will not get the ATTENTION warning |
7 | 68 message. |
69 On the Amiga you can also use a recoverable ram disk, but there is no 100% | |
70 guarantee that this works. Putting swap files in a normal ram disk (like RAM: | |
71 on the Amiga) or in a place that is cleared when rebooting (like /tmp on Unix) | |
72 makes no sense, you will lose the swap file in a crash. | |
73 | |
74 If you want to put swap files in a fixed place, put a command resembling the | |
75 following ones in your .vimrc: | |
76 :set dir=dh2:tmp (for Amiga) | |
77 :set dir=~/tmp (for Unix) | |
78 :set dir=c:\\tmp (for MS-DOS and Win32) | |
79 This is also very handy when editing files on floppy. Of course you will have | |
80 to create that "tmp" directory for this to work! | |
81 | |
82 For read-only files, a swap file is not used. Unless the file is big, causing | |
83 the amount of memory used to be higher than given with 'maxmem' or | |
84 'maxmemtot'. And when making a change to a read-only file, the swap file is | |
85 created anyway. | |
86 | |
5737 | 87 The 'swapfile' option can be reset to avoid creating a swapfile. And the |
88 |:noswapfile| modifier can be used to not create a swapfile for a new buffer. | |
89 | |
5814 | 90 :nos[wapfile] {command} *:nos* *:noswapfile* |
5737 | 91 Execute {command}. If it contains a command that loads a new |
92 buffer, it will be loaded without creating a swapfile and the | |
93 'swapfile' option will be reset. If a buffer already had a | |
94 swapfile it is not removed and 'swapfile' is not reset. | |
7 | 95 |
96 | |
97 Detecting an existing swap file ~ | |
98 | |
99 You can find this in the user manual, section |11.3|. | |
100 | |
101 | |
102 Updating the swapfile ~ | |
103 | |
104 The swap file is updated after typing 200 characters or when you have not | |
105 typed anything for four seconds. This only happens if the buffer was | |
106 changed, not when you only moved around. The reason why it is not kept up to | |
107 date all the time is that this would slow down normal work too much. You can | |
108 change the 200 character count with the 'updatecount' option. You can set | |
109 the time with the 'updatetime' option. The time is given in milliseconds. | |
110 After writing to the swap file Vim syncs the file to disk. This takes some | |
111 time, especially on busy Unix systems. If you don't want this you can set the | |
112 'swapsync' option to an empty string. The risk of losing work becomes bigger | |
113 though. On some non-Unix systems (MS-DOS, Amiga) the swap file won't be | |
114 written at all. | |
115 | |
116 If the writing to the swap file is not wanted, it can be switched off by | |
117 setting the 'updatecount' option to 0. The same is done when starting Vim | |
118 with the "-n" option. Writing can be switched back on by setting the | |
119 'updatecount' option to non-zero. Swap files will be created for all buffers | |
120 when doing this. But when setting 'updatecount' to zero, the existing swap | |
121 files will not be removed, it will only affect files that will be opened | |
122 after this. | |
123 | |
124 If you want to make sure that your changes are in the swap file use this | |
125 command: | |
126 | |
127 *:pre* *:preserve* *E313* *E314* | |
128 :pre[serve] Write all text for all buffers into swap file. The | |
164 | 129 original file is no longer needed for recovery. |
130 This sets a flag in the current buffer. When the '&' | |
131 flag is present in 'cpoptions' the swap file will not | |
132 be deleted for this buffer when Vim exits and the | |
133 buffer is still loaded |cpo-&|. | |
134 {Vi: might also exit} | |
7 | 135 |
136 A Vim swap file can be recognized by the first six characters: "b0VIM ". | |
137 After that comes the version number, e.g., "3.0". | |
138 | |
593 | 139 |
140 Links and symbolic links ~ | |
141 | |
142 On Unix it is possible to have two names for the same file. This can be done | |
143 with hard links and with symbolic links (symlinks). | |
144 | |
145 For hard links Vim does not know the other name of the file. Therefore, the | |
146 name of the swapfile will be based on the name you used to edit the file. | |
147 There is no check for editing the same file by the other name too, because Vim | |
148 cannot find the other swapfile (except for searching all of your harddisk, | |
149 which would be very slow). | |
150 | |
151 For symbolic links Vim resolves the links to find the name of the actual file. | |
152 The swap file name is based on that name. Thus it doesn't matter by what name | |
153 you edit the file, the swap file name will normally be the same. However, | |
154 there are exceptions: | |
155 - When the directory of the actual file is not writable the swapfile is put | |
156 elsewhere. | |
157 - When the symbolic links somehow create a loop you get an *E773* error | |
158 message and the unmodified file name will be used. You won't be able to | |
159 save your file normally. | |
160 | |
7 | 161 ============================================================================== |
162 2. Recovery *recovery* *E308* *E311* | |
163 | |
164 Basic file recovery is explained in the user manual: |usr_11.txt|. | |
165 | |
166 Another way to do recovery is to start Vim and use the ":recover" command. | |
167 This is easy when you start Vim to edit a file and you get the "ATTENTION: | |
168 Found a swap file ..." message. In this case the single command ":recover" | |
169 will do the work. You can also give the name of the file or the swap file to | |
170 the recover command: | |
171 *:rec* *:recover* *E305* *E306* *E307* | |
172 :rec[over] [file] Try to recover [file] from the swap file. If [file] | |
173 is not given use the file name for the current | |
174 buffer. The current contents of the buffer are lost. | |
175 This command fails if the buffer was modified. | |
176 | |
177 :rec[over]! [file] Like ":recover", but any changes in the current | |
178 buffer are lost. | |
179 | |
180 *E312* *E309* *E310* | |
181 Vim has some intelligence about what to do if the swap file is corrupt in | |
182 some way. If Vim has doubt about what it found, it will give an error | |
183 message and insert lines with "???" in the text. If you see an error message | |
184 while recovering, search in the file for "???" to see what is wrong. You may | |
185 want to cut and paste to get the text you need. | |
186 | |
187 The most common remark is "???LINES MISSING". This means that Vim cannot read | |
188 the text from the original file. This can happen if the system crashed and | |
189 parts of the original file were not written to disk. | |
190 | |
191 Be sure that the recovery was successful before overwriting the original | |
192 file or deleting the swap file. It is good practice to write the recovered | |
193 file elsewhere and run 'diff' to find out if the changes you want are in the | |
2033
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1702
diff
changeset
|
194 recovered file. Or use |:DiffOrig|. |
7 | 195 |
196 Once you are sure the recovery is ok delete the swap file. Otherwise, you | |
197 will continue to get warning messages that the ".swp" file already exists. | |
198 | |
199 {Vi: recovers in another way and sends mail if there is something to recover} | |
200 | |
2267 | 201 |
202 ENCRYPTION AND THE SWAP FILE *:recover-crypt* | |
203 | |
204 When the text file is encrypted the swap file is encrypted as well. This | |
205 makes recovery a bit more complicated. When recovering from a swap file and | |
206 encryption has been used, you will be asked to enter one or two crypt keys. | |
207 | |
208 If the text file does not exist you will only be asked to enter the crypt key | |
209 for the swap file. | |
210 | |
211 If the text file does exist, it may be encrypted in a different way than the | |
212 swap file. You will be asked for the crypt key twice: | |
213 | |
214 Need encryption key for "/tmp/tt" ~ | |
215 Enter encryption key: ****** ~ | |
216 "/tmp/tt" [crypted] 23200L, 522129C ~ | |
217 Using swap file "/tmp/.tt.swp" ~ | |
218 Original file "/tmp/tt" ~ | |
219 Swap file is encrypted: "/tmp/.tt.swp" ~ | |
220 If you entered a new crypt key but did not write the text file, ~ | |
221 enter the new crypt key. ~ | |
222 If you wrote the text file after changing the crypt key press enter ~ | |
223 to use the same key for text file and swap file ~ | |
224 Enter encryption key: ~ | |
225 | |
226 You can be in one of these two situations: | |
227 | |
228 1. The encryption key was not changed, or after changing the key the text file | |
229 was written. You will be prompted for the crypt key twice. The second | |
230 time you can simply press Enter. That means the same key is used for the | |
231 text file and the swap file. | |
232 2. You entered a new encryption key, but did not save the text file. Vim will | |
233 then use the new key for the swap file, and the text file will still be | |
234 encrypted with the old key. At the second prompt enter the new key. | |
235 | |
236 Note that after recovery the key of the swap file will be used for the text | |
237 file. Thus if you write the text file, you need to use that new key. | |
238 | |
239 | |
14421 | 240 vim:tw=78:ts=8:noet:ft=help:norl: |