Why does vim create <filename>~
files? Is there a way to disable that?
If it's for backup (or something), I use git for that.
Also, these .<filename.with.path.hints>.swp
files too.
How do I tell vim not to create those, or at the least to cleanup after itself?
EDIT
whoops, duplicate:
I adopted rogeriopvl's answer from there.
verbatim copy:
set nobackup "no backup files
set nowritebackup "only in case you don't want a backup file while editing
set noswapfile "no swap files
I'd strongly recommend to keep working with swap files (in case Vim crashes).
You can set the directory where the swap files are stored, so they don't clutter your normal directories:
See also
Put this in your .vimrc configuration file.
This answer applies to using gVim on Windows 10. I cannot guarantee the same results for other operating systems.
Add:
To your _vimrc file.
Note: This is the direct answer to the question (for Windows 10) and probably not the safest thing to do (read the other answers), but this is the fastest solution in my case.
I made a plugin called "noswapsuck" that only enables the swapfile when the buffer contains unsaved changes. Once changes have been saved, the swapfile is cleared. Hence, swapfiles which contain the same content as the file on disk will be removed.
Get it here:
noswapsuck.vim
It has been working well for me, but I have never publicised it before, so I would welcome feedback.
Advantages:
Disadvantages:
If the buffer has a swapfile, it will not be detected when the file is first opened. It will only be detected when(Solved: We now check for a pre-existing swapfile when a buffer is opened, by temporarily turning theswapfile
is enabled, which is when you start to edit the buffer. That is annoyingly late, and will interrupt you.swapfile
option on again.)If you are working in an environment where you want to minimise disk-writes (e.g. low power, or files mounted over a network, or editing a huge file) then it is not ideal to keep removing and re-creating the swap file on every save and edit. In such situations, you can do:
which will keep the swapfile after a write, but will still remove it when the buffer loses focus.
By the way, I have another little plugin
:DiffAgainstFileOnDisk
which can be pretty useful after hitting(r)ecover
, to check if the buffer you recovered is newer or older than the existing file, or identical to it.; For Windows Users to back to temp directory
On Windows add following lines to _vimrc