If I restart vim after a crash, it'll tell me that a swap file for my file exists, and ask me what to do--open anyway, recover the file, quit, abort, etc. Sometimes it gives me the option to delete the swap file, and that's usually the option I need. Other times, however, it doesn't give me that option for some reason. Why is that, and how can I get vim to allow me to delete swap files from within vim? (Because deleting it manually is a pain.)


From :help swap-exists:

D  Delete the swap file.  Use this when you are sure you no longer need it.
   For example, when it doesn't contain changes, or when the file itself is
   newer than the swap file.
      On Unix this choice is only offered when the process that created the
   swap file does not appear to be running.

So it sounds like Vim somehow believes another Vim process is still actively running on that file.

  • 3
    Oh cool. I see now that when my SSH connection was lost, the vim process was still there in the background somehow. – Jonathan Apr 30 '14 at 14:17
  • +1 for the :help swap-exists. I was always confused about the options. – wisbucky Nov 20 '19 at 2:44

Your second question: "how can I get vim to allow me to delete swap files from within vim"

is answered here: What's the easiest way to delete Vim swapfiles I've already recovered from?

  • Those answers assume Vim is presenting "delete" as one of the options when opening the file, which it is not--the whole basis for this question. – Dominick Pastore May 14 '20 at 17:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.