VIM Swap and backup files
08Aug06
If you are programming in a enterprise enviroment and come from a linux background, I bet you have ran into the situation where you arn’t sure if VIM is going to leave trash files around.
VIM on many different types of installations will create both swap files and backup files.
How to disable VIM swap and backup files:
Go into your _vimrc file. Add these lines to the bottom –
set nobackup
set nowritebackup
set noswapfile
Filed under: VIM | 10 Comments
great tip! the vim documentation has a section about this but it’s down at the moment. this was a real life saver!
Thank you. This is very helpful and was quite easy to find on the Net. Thanks a lot.
Thanks for the information, it helped out a lot. I would like to add a few comments about the above information.
set nobackup
Having this set will not leave any additional file(s) around after having closed VIM. This is what most people might be looking to have set.
set nowritebackup
I do not set this one. The default is :set writebackup This will keep a backup file while the file is being worked. Once VIM is closed; the backup will vanish.
set noswapfile
From the VIM help file.
- Don’t use this for big files.
- Recovery will be impossible!
In essence; if security is a concern, use noswapfile. Keep in mind that this option will keep everything in memory.
Once again; thanks for the information, it was quite useful.
Regards,
Nix
Thank you for this!
Can anyone offer a tip to solve this problem:
when I open a file on a network share vim gives error E325 related to the swap file — see error below.
I would like to keep backups (and even the swap) if possible. I just want to avoid this error. Following the advice in this post solves the problem, so my question is can I always redirect any swap or backup files to a known and static local location? If so, how? Thanks.
E325: ATTENTION
Found a swap file by the name “.geocode.py.swp”
owned by: rbronosky dated: Fri Sep 7 17:17:37 2007
file name: geocode.py
modified: YES
user name: rbronosky
process ID: 6490
While opening file “geocode.py”
dated: Fri Sep 7 17:17:04 2007
(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 geocode.py”
to recover the changes (see “:help recovery”).
If you did this already, delete the swap file “.geocode.py.swp”
to avoid this message.
Swap file “.geocode.py.swp” already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:
I’d strongly advise against turning off backups on shared boxes. Backup files are so useful, even if you don’t look at the backup file, it’s a marker that a file has changed.
“Add these lines to the bottom”. This is very important. I puted it before:
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
and didn’t work.
thanks a lot.
I just setup a backup directory. btw thank you nix for clearing the details up. To set a backp dir:
set backupdir=$TEMP,$TMP,.