maxfowler
maxfowler

Reputation: 1298

Is there a way to disable vim's swap file warning?

Whenever I run

git commit --amend

and I think some other commands also

I get a warning from vim before I edit the commit message, that says something like:

E325: ATTENTION
Found a swap file by the name "~/Desktop/code/web/.git/.COMMIT_EDITMSG.swp"

I always ignore the warning, and just write my commit message and save the file. Is there a way I can disable this warning permanently?

Upvotes: 3

Views: 3580

Answers (4)

Jim Stewart
Jim Stewart

Reputation: 17323

You can also delete the offending swap file from the prompt inside Vim, when it happens. You'll see something like this:

E325: ATTENTION
Found a swap file by the name "~/.vim/tmp/test.txt.swp"
          owned by: jim   dated: Mon Nov 21 00:54:03 2016
         [cannot be read]
While opening file "test.txt"
             dated: Mon Nov 21 00:53:38 2016

(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 test.txt"
    to recover the changes (see ":help recovery").
    If you did this already, delete the swap file "/Users/jim/.vim/tmp/test.txt.swp"
    to avoid this message.

Swap file "~/.vim/tmp/test.txt.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:

If you hit D here, it will delete the swap file that caused the error message, and you won't see it again for that one file. You can then write your file again, and you won't get the error.

Not directly related to your question, but something you may want to consider is changing the directory option so that swap files aren't created in the same directory as the file you're editing. I use:

set directory=~/.vim/tmp,/var/tmp,/tmp

Which will try using those directories, in order. This helps keep swap files in one place, so it's easier to delete them all at once, if Vim crashes while you have a bunch of files open:

rm ~/.vim/tmp/*

It also prevents swap files from ending up in your Git tree, without worrying about .gitignore.

Upvotes: 1

Andy Ray
Andy Ray

Reputation: 32066

Add this to your .vimrc

" Don't let Vim's "Found a swap file" message block input
set shortmess=A

And never worry about the annoying swapfile message again!

Upvotes: 3

imbichie
imbichie

Reputation: 1606

if you are editing the files with vim/gvim editor, then set the below command in your .vimrc/.gvimrc file to avoid the generation of swap files

set noswapfile

Upvotes: 1

maxfowler
maxfowler

Reputation: 1298

Deleting the swap file gets rid of the warning:

rm ~/Desktop/code/web/.git/.COMMIT_EDITMSG.swp

Upvotes: 4

Related Questions