E325: ATTENTION Found a swap file by the name “.notes.swp” owned by: james dated: Fri Dec 3 17:38:07 2010 file name: ~james/school/se/project-dir/rottencucumber/doc/notes modified: no user name: james host name: james-laptop process ID: 2251 (still running) While opening file “notes” dated: Fri Dec 3 18:46:10 2010 NEWER than swap file!
(1) Another program may be editing the same file. If this is the case, be 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 notes” to recover the changes (see “:help recovery”). If you did this already, delete the swap file “.notes.swp” to avoid this message.
Swap file “.notes.swp” already exists! [O]pen Read-Only, (E)dit anyway, ®ecover, (Q)uit, (A)bort:
This message is actually pretty important if you care about not losing text you’ve potentially not saved. It should not be considered annoying, and should not cause you to hastily delete the swap file or configure vim to run without it.
Any file you edit with vim will have a corresponding swap file while you edit, which vim uses to keep track of changes. When you quit editing a file, vim will automatically discard the corresponding swap file. Therefore, the existence of a swap file, and your attempt to write overtop the original file, should be cause for consideration and appropriate action.
The two scenarios presented in the message (E325: ATTENTION Found a swap file) are actually quite common: (1) either another vim program is editing the very same file you’re trying to edit (it could actually be another person - in which case it really wouldn’t make sense to just blindly delete the swap file - or it could be you in another terminal window or tab), or (2) a previous vim session crashed (most often this happens when you’re editing remotely, and the network session is severed - in which case the vim session was not exited normally, and the .swp file remains behind; another example of this second scenario is that you’ve accidentally closed the terminal window or tab that had an active or backgrounded vim session).
When I encounter this message I first think about whether I am editing this file in another terminal window or tab, as I normally operate with several terminal windows with several tabs each:
If I realize that I am editing in another place, and can return to it, I then press the q key to (Q)uit this additional session, and return to editing via the original vim session. Sometimes if I am not entirely sure, I (Q)uit and then run jobs to verify whether I am running vim in the exact same terminal; if nothing comes up, I run ps -ef | grep vim to check whether I am running vim elsewhere (i.e. in another terminal window or tab). The point is, I always try to resume editing via the original vim session.
Pressing r, you will see a message like this:
Swap file ".notes.swp" already exists! "notes" 18L, 46C Using swap file ".notes.swp" Original file "/private/tmp/notes" Recovery completed. Buffer contents equals file contents. You may want to delete the .swp file now. Press ENTER or type command to continueIf, on the other hand, I am no longer faced with those options, because I am at the shell prompt, then I run vim with the -r option, as follows:
vim -r notesThe resultant message will be similar:
Using swap file ".notes.swp" Original file "/private/tmp/notes" Recovery completed. Buffer contents equals file contents. You may want to delete the .swp file now. Press ENTER or type command to continueNote: If Vim has doubt about what it found, it will give an error message and insert lines with “???” in the text. If you see an error message while recovering, search in the file for “???” to see what is wrong. You may want to cut and paste to get the text you need.
The most common remark is “???LINES MISSING”. This means that Vim cannot read the text from the original file. This can happen if the system crashed and parts of the original file were not saved.
That said, I have never seen those ??? marks, so this must be a truly rare occurrence.
Next, force-quit this vim session:
:q!Next, compare the two files;
diff notes notes2If the diff returns nothing, that means there is no difference, and it is safe to remove both the swap file and the second file:
rm .notes.swp notes2At this point, open the original file and proceed as if there had never been a problem:
vim notesIf the diff returns something, that means the original file (via the swap file) had changes that, thanks to the recover, have been saved to the second file.
Since those changes are captured in the second file you are safe to delete the swap file and overwrite the original file with the second one:
rm .notes.swp remove .notes.swp? y mv notes2 notes overwrite notes? (y/n [n]) yAt this point, open the original file and proceed as if there had never been a problem:
vim notesThis seems like a lot of work, but once you get used to the workflow it takes like 20 seconds max.