Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: Stop "existing swap file" warnings

Tags:

vim

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?"

like image 590
tdavis Avatar asked Jul 08 '09 13:07

tdavis


People also ask

Where are SWP files stored in Linux?

swp is a swap file, containing the unsaved changes. While editing a file, you can see which swap file is being used by entering :sw . The location of this file is set with directory option. The default value is .,~/tmp,/var/tmp,/tmp .

What is swap file management?

A swap file is a system file that creates temporary storage space on a solid-state drive or hard disk when the system runs low on memory. The file swaps a section of RAM storage from an idle program and frees up memory for other programs.


2 Answers

In .vimrc add:

set shortmess+=A 

From the docs :help shortmess:

A don't give the "ATTENTION" message when an existing swap file is found.

like image 197
Izzy Avatar answered Sep 25 '22 02:09

Izzy


There is plugin that can "Just do the right thing" automatically for Vim swapfiles: vim-autoswap.

From the homepage:

Dealing with swap files is annoying. Most of the time you have to deal with a swap file because you either have the same file open in another window or it is a swap file left there by a previous crash.

This plugin does for you what you would do in these cases:

  • Is file already open in another Vim session in some other window?
  • If so, swap to the window where we are editing that file.
  • Otherwise, if swapfile is older than file itself, just get rid of it.
  • Otherwise, open file read-only so we can have a look at it and may save it.
like image 23
gioele Avatar answered Sep 24 '22 02:09

gioele