careful not to end up with two ~
different instances of the same file when making changes. ~
Quit, or continue with caution. ~
~
(2) An edit session for this file crashed. ~
If this is the case, use ":recover" or "vim -r main.c" ~
to recover the changes (see ":help recovery"). ~
If you did this already, delete the swap file ".main.c.swp" ~
to avoid this message. ~
You get this message, because, when starting to edit a file, Vim checks if a
swap file already exists for that file. If there is one, there must be
something wrong. It may be one of these two situations.
1. Another edit session is active on this file. Look in the message for the
line with "process ID". It might look like this:
process ID: 12559 (still running) ~
The text "(still running)" indicates that the process editing this file
runs on the same computer. When working on a non-Unix system you will not
get this extra hint. When editing a file over a network, you may not see
the hint, because the process might be running on another computer. In
those two cases you must find out what the situation is yourself.
If there is another Vim editing the same file, continuing to edit will
result in two versions of the same file. The one that is written last will
overwrite the other one, resulting in loss of changes. You better quit
this Vim.
2. The swap file might be the result from a previous crash of Vim or the
computer. Check the dates mentioned in the message. If the date of the
swap file is newer than the file you were editing, and this line appears:
modified: YES ~
Then you very likely have a crashed edit session that is worth recovering.
If the date of the file is newer than the date of the swap file, then
either it was changed after the crash (perhaps you recovered it earlier,
but didn't delete the swap file?), or else the file was saved before the
crash but after the last write of the swap file (then you're lucky: you
don't even need that old swap file). Vim will warn you for this with this
extra line:
NEWER than swap file! ~
NOTE that in the following situation Vim knows the swap file is not useful and
will automatically delete it:
- The file is a valid swap file (Magic number is correct).
- The flag that the file was modified is not set.
- The process is not running.
You can programmatically deal with this situation with the |FileChangedShell|
autocommand event.
UNREADABLE SWAP FILE ~
Sometimes the line
[cannot be read] ~
will appear under the name of the swap file. This can be good or bad,
depending on circumstances.
It is good if a previous editing session crashed without having made any
changes to the file. Then a directory listing of the swap file will show
that it has zero bytes. You may delete it and proceed.
It is slightly bad if you don't have read permission for the swap file. You
may want to view the file read-only, or quit. On multi-user systems, if you
yourself did the last changes under a different login name, a logout
followed by a login under that other name might cure the "read error". Or
else you might want to find out who last edited (or is editing) the file and
have a talk with them.
It is very bad if it means there is a physical read error on the disk
containing the