annotate runtime/doc/recover.txt @ 0:76efa0be13f1

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