robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Eisuke Kawashimadocs: adjust modelines for HTML rendering #396497e778205ab

master
12.4 KiB317 linesraw
1*usr_11.txt*	Nvim
2
3
4		     VIM USER MANUAL	by Bram Moolenaar
5
6
7			   Recovering from a crash
8
9
10Did your computer crash?  And you just spent hours editing?  Don't panic!  Vim
11stores enough information to be able to restore most of your work.  This
12chapter shows you how to get your work back and explains how the swap file is
13used.
14
15|11.1|	Basic recovery
16|11.2|	Where is the swap file?
17|11.3|	Crashed or not?
18|11.4|	Further reading
19
20     Next chapter: |usr_12.txt|  Clever tricks
21 Previous chapter: |usr_10.txt|  Making big changes
22Table of contents: |usr_toc.txt|
23
24==============================================================================
25*11.1*	Basic recovery
26
27In most cases recovering a file is quite simple, assuming you know which file
28you were editing (and the harddisk is still working).  Start Vim on the file,
29with the "-r" argument added: >
30
31	vim -r help.txt
32
33Vim will read the swap file (used to store text you were editing) and may read
34bits and pieces of the original file.  If Vim recovered your changes you will
35see these messages (with different file names, of course):
36
37	Using swap file ".help.txt.swp" ~
38	Original file "~/vim/runtime/doc/help.txt" ~
39	Recovery completed. You should check if everything is OK. ~
40	(You might want to write out this file under another name ~
41	and run diff with the original file to check for changes) ~
42	You may want to delete the .swp file now. ~
43
44To be on the safe side, write this file under another name: >
45
46	:write help.txt.recovered
47
48Compare the file with the original file to check if you ended up with what you
49expected.  Diff mode is very useful for this |08.7|.  For example: >
50
51	:write help.txt.recovered
52	:edit #
53	:diffsp help.txt
54
55Watch out for the original file to contain a more recent version (you saved
56the file just before the computer crashed).  And check that no lines are
57missing (something went wrong that Vim could not recover).
58   If Vim produces warning messages when recovering, read them carefully.
59This is rare though.
60
61If the recovery resulted in text that is exactly the same as the file
62contents, you will get this message:
63
64	Using swap file ".help.txt.swp" ~
65	Original file "~/vim/runtime/doc/help.txt" ~
66	Recovery completed. Buffer contents equals file contents. ~
67	You may want to delete the .swp file now. ~
68
69This usually happens if you already recovered your changes, or you wrote the
70file after making changes.  It is safe to delete the swap file now.
71
72It is normal that the last few changes can not be recovered.  Vim flushes the
73changes to disk when you don't type for about four seconds, or after typing
74about two hundred characters.  This is set with the 'updatetime' and
75'updatecount' options.  Thus when Vim didn't get a chance to save itself when
76the system went down, the changes after the last flush will be lost.
77
78If you were editing without a file name, give an empty string as argument: >
79
80	vim -r ""
81
82You must be in the right directory, otherwise Vim can't find the swap file.
83
84==============================================================================
85*11.2*	Where is the swap file?
86
87Vim can store the swap file in several places.  To find it, change to the
88directory of the file, and use: >
89
90	vim -r
91
92Vim will list the swap files that it can find.  It will also look in other
93directories where the swap file for files in the current directory may be
94located.  It will not find swap files in any other directories though, it
95doesn't search the directory tree.
96   The output could look like this:
97
98	Swap files found: ~
99	   In current directory: ~
100	1.    .main.c.swp ~
101		  owned by: mool   dated: Tue May 29 21:00:25 2001 ~
102		 file name: ~mool/vim/vim6/src/main.c ~
103		  modified: YES ~
104		 user name: mool   host name: masaka.moolenaar.net ~
105		process ID: 12525 ~
106	   In directory ~/tmp: ~
107	      -- none -- ~
108	   In directory /var/tmp: ~
109	      -- none -- ~
110	   In directory /tmp: ~
111	      -- none -- ~
112
113If there are several swap files that look like they may be the one you want to
114use, a list is given of these swap files and you are requested to enter the
115number of the one you want to use.  Carefully look at the dates to decide
116which one you want to use.
117   In case you don't know which one to use, just try them one by one and check
118the resulting files if they are what you expected.
119
120
121USING A SPECIFIC SWAP FILE
122
123If you know which swap file needs to be used, you can recover by giving the
124swap file name.  Vim will then find out the name of the original file from
125the swap file.
126
127Example: >
128	vim -r .help.txt.swo
129
130This is also handy when the swap file is in another directory than expected.
131Vim recognizes files with the pattern "*.s[uvw][a-z]" as swap files.
132
133If this still does not work, see what file names Vim reports and rename the
134files accordingly.  Check the 'directory' option to see where Vim may have
135put the swap file.
136
137	Note:
138	Vim tries to find the swap file by searching the directories in the
139	'dir' option, looking for files that match "filename.sw?".  If
140	wildcard expansion doesn't work (e.g., when the 'shell' option is
141	invalid), Vim does a desperate try to find the file "filename.swp".
142	If that fails too, you will have to give the name of the swapfile
143	itself to be able to recover the file.
144
145==============================================================================
146*11.3*	Crashed or not?					*ATTENTION* *E325*
147
148Vim tries to protect you from doing stupid things.  Suppose you innocently
149start editing a file, expecting the contents of the file to show up.  Instead,
150Vim produces a very long message:
151
152		E325: ATTENTION ~
153	Found a swap file by the name ".main.c.swp" ~
154		  owned by: mool   dated: Tue May 29 21:09:28 2001 ~
155		 file name: ~mool/vim/vim6/src/main.c ~
156		  modified: no ~
157		 user name: mool   host name: masaka.moolenaar.net ~
158		process ID: 12559 (still running) ~
159	While opening file "main.c" ~
160		     dated: Tue May 29 19:46:12 2001 ~
161 ~
162	(1) Another program may be editing the same file. ~
163	    If this is the case, be careful not to end up with two ~
164	    different instances of the same file when making changes. ~
165	    Quit, or continue with caution. ~
166 ~
167	(2) An edit session for this file crashed. ~
168	    If this is the case, use ":recover" or "vim -r main.c" ~
169	    to recover the changes (see ":help recovery"). ~
170	    If you did this already, delete the swap file ".main.c.swp" ~
171	    to avoid this message. ~
172
173You get this message, because, when starting to edit a file, Vim checks if a
174swap file already exists for that file.  If there is one, there must be
175something wrong.  It may be one of these two situations.
176
1771. Another edit session is active on this file.  Look in the message for the
178   line with "process ID".  It might look like this:
179
180		process ID: 12559 (still running) ~
181
182   The text "(still running)" indicates that the process editing this file
183   runs on the same computer.  When working on a non-Unix system you will not
184   get this extra hint.  When editing a file over a network, you may not see
185   the hint, because the process might be running on another computer.  In
186   those two cases you must find out what the situation is yourself.
187      If there is another Vim editing the same file, continuing to edit will
188   result in two versions of the same file.  The one that is written last will
189   overwrite the other one, resulting in loss of changes.  You better quit
190   this Vim.
191
1922. The swap file might be the result from a previous crash of Vim or the
193   computer.  Check the dates mentioned in the message.  If the date of the
194   swap file is newer than the file you were editing, and this line appears:
195
196		modified: YES ~
197
198   Then you very likely have a crashed edit session that is worth recovering.
199      If the date of the file is newer than the date of the swap file, then
200   either it was changed after the crash (perhaps you recovered it earlier,
201   but didn't delete the swap file?), or else the file was saved before the
202   crash but after the last write of the swap file (then you're lucky: you
203   don't even need that old swap file).  Vim will warn you for this with this
204   extra line:
205
206      NEWER than swap file! ~
207
208
209NOTE that in the following situation Vim knows the swap file is not useful and
210will automatically delete it:
211- The file is a valid swap file (Magic number is correct).
212- The flag that the file was modified is not set.
213- The process is not running.
214
215You can programmatically deal with this situation with the |FileChangedShell|
216autocommand event.
217
218
219UNREADABLE SWAP FILE ~
220
221Sometimes the line
222
223	[cannot be read] ~
224
225will appear under the name of the swap file.  This can be good or bad,
226depending on circumstances.
227
228It is good if a previous editing session crashed without having made any
229changes to the file.  Then a directory listing of the swap file will show
230that it has zero bytes.  You may delete it and proceed.
231
232It is slightly bad if you don't have read permission for the swap file.  You
233may want to view the file read-only, or quit.  On multi-user systems, if you
234yourself did the last changes under a different login name, a logout
235followed by a login under that other name might cure the "read error".  Or
236else you might want to find out who last edited (or is editing) the file and
237have a talk with them.
238
239It is very bad if it means there is a physical read error on the disk
240containing the swap file.  Fortunately, this almost never happens.
241You may want to view the file read-only at first (if you can), to see the
242extent of the changes that were "forgotten".  If you are the one in charge of
243that file, be prepared to redo your last changes.
244
245
246WHAT TO DO?					*swap-exists-choices*
247
248If dialogs are supported you will be asked to select one of six choices:
249
250  Swap file ".main.c.swp" already exists! ~
251  [O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort, (D)elete it: ~
252
253O  Open the file readonly.  Use this when you just want to view the file and
254   don't need to recover it.  You might want to use this when you know someone
255   else is editing the file, but you just want to look in it and not make
256   changes.
257
258E  Edit the file anyway.  Use this with caution!  If the file is being edited
259   in another Vim, you might end up with two versions of the file.  Vim will
260   try to warn you when this happens, but better be safe than sorry.
261
262R  Recover the file from the swap file.  Use this if you know that the swap
263   file contains changes that you want to recover.
264
265Q  Quit.  This avoids starting to edit the file.  Use this if there is another
266   Vim editing the same file.
267      When you just started Vim, this will exit Vim.  When starting Vim with
268   files in several windows, Vim quits only if there is a swap file for the
269   first one.  When using an edit command, the file will not be loaded and you
270   are taken back to the previously edited file.
271
272A  Abort.  Like Quit, but also abort further commands.  This is useful when
273   loading a script that edits several files, such as a session with multiple
274   windows.
275
276D  Delete the swap file.  Use this when you are sure you no longer need it.
277   For example, when it doesn't contain changes, or when the file itself is
278   newer than the swap file.
279      On Unix this choice is only offered when the process that created the
280   swap file does not appear to be running.
281
282If you do not get the dialog (you are running a version of Vim that does not
283support it), you will have to do it manually.  To recover the file, use this
284command: >
285
286	:recover
287
288
289Vim cannot always detect that a swap file already exists for a file.  This is
290the case when the other edit session puts the swap files in another directory
291or when the path name for the file is different when editing it on different
292machines.  Therefore, don't rely on Vim always warning you.
293
294If you really don't want to see this message, you can add the 'A' flag to the
295'shortmess' option.  But it's very unusual that you need this.
296
297For programmatic access to the swap file, see |swapinfo()|.
298
299==============================================================================
300*11.4*	Further reading
301
302|swap-file|	An explanation about where the swap file will be created and
303		what its name is.
304|:preserve|	Manually flushing the swap file to disk.
305|:swapname|	See the name of the swap file for the current file.
306'updatecount'	Number of key strokes after which the swap file is flushed to
307		disk.
308'updatetime'	Timeout after which the swap file is flushed to disk.
309'directory'	List of directory names where to store the swap file.
310
311==============================================================================
312
313Next chapter: |usr_12.txt|  Clever tricks
314
315Copyright: see |manual-copyright|
316
317vim:tw=78:ts=8:noet:ft=help:norl: