How to make vim save its *~ and *.swp files in a separate directory
If you, like me, are tired of vim’s pesky backup and swap files littering your project directory then you too should create a .vimtmp directory in your home folder and add this little snippet to your .vimrc
" Store vim backups and *.swp files in ~/.vimtmp with a unique name
set backupdir=~/.vimtmp//
set directory=~/.vimtmp//
Now all your backup and swap files will be stored in ~/.vimtmp/ and prefixed with a formatted file path, eg, %some%where%on%my%computer%some_file.ext.swp
Posted in Utilities at August 17th, 2009. Trackback URI: trackback Tags: vim, vim backup, vimrc Written by: Patrik Hedman

Just for future reference, you might also add that you can do something like
set backupdir=~/.vimtmp,.
set directory=~/.vimtmp,.
and the “.” will default to the current directory just in case you’ve moved your vim rc file to a new computer and haven’t recreated your backup directory.
dude
on October 26th, 2009 at 5:39 pm
Cool, I didn’t know about that.
polly
on October 28th, 2009 at 10:08 am