set backupdir=./.backup,.,/tmp
set directory=.,./.backup,/tmp
This way, if you want your backups to be neatly grouped, just create a directory called '.backup' in your working directory. Vim will stash backups there. The 'directory' option controls where swap files go. If your working directory is not writable, Vim will put the swap file in one of the specified places.
(http://vim.wikia.com/wiki/Remove_swap_and_backup_files_from_...)
set backupdir=~/.vim/backup//
set directory=~/.vim/swp//
The double tailing slash will store files using full paths so if you edit two different models.py files you won't clobber your swap or backups.But, I soon realized that noswapfile has another problem which caused me to disable it after all: it will allow you to open same file in more then one vim editor instance. And this is really asking for troubles.
It is less of a problem with graphical vim as you can use "autoread" to sync changes between instances, but it is a disaster on console.
What really ends up happening is I try to edit a file and something annoying pops up telling me about something requiring my attention (swap file already exists .. read only mode .. bla bla). In other words, it's just a distraction, most of the time.
You can configure it to put your swap files in a canonical dir, instead of polluting the directory you're editing files in:
set backupdir=/var/tmp,/tmp
set directory=/var/tmp,/tmp
Now you can just nuke the swap files in one swoop:
rm -rf /var/tmp/*.swp
It can?
set nobackup set noswapfile
backup files are one thing, but turning off swap files is a terrible idea. vim can crash, you can accidentally close the window, your ssh session can die, etc. if you exit vim cleanly then the swap files will be transparent, so i don't see the point in disabling them.