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: , , Written by: Patrik Hedman

2 Responses to “How to make vim save its *~ and *.swp files in a separate directory”

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.

dudeNo Gravatar on October 26th, 2009 at 5:39 pm

Cool, I didn’t know about that.

pollyNo Gravatar on October 28th, 2009 at 10:08 am

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

pastbedti.me is using WP-Gravatar