tags:

views:

832

answers:

5

I have no idea why, but it seems that no matter how I quit out of Vim, it always leaves the swap files behind. So, whenever I open that file again, I get an irritating error about an existing swap file. Every time I have to choose "delete". I really wish this would stop. Is there anything I can put in my .vimrc to tell it, "just delete the swap file if it exists and leave me alone?"

+5  A: 

See the VIM recovery manual entry. You shouldn't be seeing these files normally, unless

  1. your VIM instance is crashing
  2. you're inadvertently running two VIM instances against the same file

I quite often do the latter, running 2 VIMs against the same file, in two terminals, without realising it. The 'swap file' message is the indicator that I'm doing this.

Perhaps you've got a VIM session running (backgrounded?) that you've forgotten about ?

Brian Agnew
Isn't a swap file different for a backup file? You leave a swap file around if vim crashed before closing the buffer properly.
nik
So I've just launched 'vi Test.java', then background-ed it. Then I launch another 'vi Test.java'. And I get "Swap file .Test.java.swp already exists", which makes sense, I think
Brian Agnew
The swap file is created when opening a document in vim and deleted when the document is closed properly.
Corban Brook
@Nik - my original answer referred to backup files. Is that what you're commenting about ?
Brian Agnew
+10  A: 

Command-Q on the Mac OS quits the Terminal window, and crashes every application running in the window.

To quit VIM, you have to use ordinary VIM commands like :q.

S.Lott
As simple as possible, but not simpler.
Tom
+3  A: 

set noswapfile

gregf
A: 

Put this in your vimrc file.

if has("win32") || has("win64")
    set directory=$TMP
else
    set directory=/tmp
end
Lolindrath
A: 

in .vimrc add set shortmess+=A

Izzy