Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sometimes Vim crashes and leaves me a swapfile. That's awesome. Then I open the file I was editing and Vim asks me if I want to recover. I do, thanks. When it's done, Vim tells me,

You may want to delete the .swp file now.

Why, yes, I do. How do I do that? I figured it would just start using the old swapfile as a swapfile again and clean it up when I quit, but that's not true. It makes a new one, cleans that one up, and when I open the file again it prompts me again to recover from the first one.

Surely I'm missing something.

share|improve this question

7 Answers 7

up vote 10 down vote accepted

A slightly simpler way would be to do this:

From the terminal emulator:

vim filename

Then if you choose recover, and you want to delete the swap then you first write the file and then do this from within vim:

:e          // no argument needed. It assumes the current buffer.

...and choose delete this time. I just found out about this, and I think I'll do that from now on. Then I won't accidentally overwrite a working file either, if the recovery turned out corrupt (though I've never tried that before).

There are also relevant tips on this question on Stack Overflow. (where I found this tip)

share|improve this answer
Brilliant! Thanks! –  Peeja Dec 13 '13 at 15:43

No, AFAIK you're missing nothing. Vim continues to keep the swapfile as a backup until you explicitly delete it.

Simply save and quit and reopen the same file again. You'll be prompted (again) with

[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort, (D)elete it

Now just press d :)

share|improve this answer
Really? I mean, I knew that. But that's stupid. It's certainly not "simple". –  Peeja Sep 27 '12 at 15:12
I don't know any better way to do that and I can't even find any reference to a command to delete swapfiles. If nobody provide a better answer you can always setup a mapping by yourself... –  Avio Sep 27 '12 at 15:23
I guess I'll have to. Thanks for the answer! –  Peeja Sep 27 '12 at 15:30
By the way, what's the difference between quit and abort? –  trusktr Oct 3 '13 at 5:10
hmm Vim never prompts me to delete the swap file –  Gregory Pakosz Jun 20 '14 at 13:55

Vim, like most Unix commands, is simple and explicit, rather than assuming and implicit.

You recover with (r). It you don't like the recovery or the recovery is corrupt, you can discard it. If you do like it, you can save the file. The recovery file is not deleted for you because this is not explicit and will not be correct for 100% of situations.

So you (r)ecover, (w)rite and (q)uit, then either edit again and choose (d)elete or "rm .myfile.js.swp" and edit again. This is quick to do and is always, from Vim's point of view, 100% correct behaviour.

share|improve this answer
Okay, then is there a way to get vim to give me the path to the swap file? I'm happy to run a second command to delete the swapfile (in fact, I like the explicitness of that), but I'd like a command to delete the swapfile wherever it is. For instance, I've got a separate swapfile directory. If two open files have the same basename, I can't programmatically decide which is the correct swapfile for the current buffer. –  Peeja Sep 27 '13 at 14:33
True, but providing a simple "Recover and delete" option would be nice. It's also probably easy tom implement. I'll do it someday when I'm done going to school if it hasn't been done already. –  trusktr Oct 3 '13 at 5:09

Type ls +A which lists ALL the files in the directory

type rm .whatever.your.swp is and press enter

Its that simple.

Any file that shows with . in front is a hidden file and is not normally seen.

Remember that changes are immediate and permanent so be careful.

share|improve this answer
Did you mean ls -a ? –  Kevin Panko Dec 21 '13 at 17:45
That's not very simple, though. I have to leave Vim, navigate the swap directory, remember the name of the file, and possibly decide whether it's file.swp or file.swo. Then I have to get back to where I was. Hitting :e is a much simpler solution. –  Peeja Dec 21 '13 at 19:41

To Clean out ALL vim Swap files in a Dir:

If you are sure you don't need any vim swap files in a directory and want to get rid of them you can use the following command in the directory while vim is not running.

find ./ -type f -name "\.*sw[klmnop]" -delete

Some inspiration and thoughts came from: https://groups.google.com/forum/#!topic/vim_use/JBHSs3kPPJU

'klmnop' may be overkill, but that usually ensures I get all of them.

share|improve this answer

From the manual :h swap:

You can see the name of the current swap file being used with the command: :sw[apname]

share|improve this answer

You can use,

rm -f .<filename>.<ext>.swp


rm -f .rc.local.swp
share|improve this answer
This technically works, but it's nowhere near as easy at the current accepted answer. –  Peeja Mar 18 at 14:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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