How can I see the option in Vim to "[D]elete" a swap file?

339 views Asked by At

When I open a file for which Vim sees that there is a swap file present, it warns me and gives me some options, like "[A]bort" and "[E]dit anyways". However, one option it used to show me but no longer does is to "[D]elete" the swap file. How can I get it to show this option again?

1

There are 1 answers

0
jeremysprofile On BEST ANSWER

As posted on the vi stack exchange site by Martin Tournoij:

The "Delete it" option isn't displayed if the Vim process is still running; I can't find this documented anywhere but I looked it up in the source code; from memline.c, line 4512 (slightly simplified):

do_dialog(
    [..]
    process_still_running
        ? (char_u *)_("&Open Read-Only\n&Edit anyway\n&Recover\n&Quit\n&Abort") :
          (char_u *)_("&Open Read-Only\n&Edit anyway\n&Recover\n&Delete it\n&Quit\n&Abort"), [..]);

The swap file embeds the process ID which created it, and if a process with that PID still exists it considers the process to be "running".

The swap message should display this information:

E325: ATTENTION
Found a swap file by the name "~/.vim/tmp/swap/swapy.swp"
          owned by: martin   dated: Fri Sep  8 22:13:35 2017
         file name: ~martin/swapy
          modified: no
         user name: martin   host name: arch.arp242.net
        process ID: 17355 (still running)
While opening file "swapy"
             dated: Fri Sep  8 22:13:35 2017

Note the process ID: 17355 (still running) line.


The most likely scenario is that you have another Vim instance running somewhere :-) You could kill it if you can't find it.

There is a small chance that the PID got re-used by another process though, in which case your only option is to quit Vim, manually remove the swap file, and restart it again:

$ rm ~/.vim/tmp/swap/swapy.swp