- Lefty, 24 Sep 2013
Found this gem on StackOverflow today - added it to my .vimrc immediately.
I’ve always been mildly annoyed that vim leaves .swp files laying around in the current directory. True, they’re prefixed with “.”, so normally they wouldn’t show up, but due to muscle memory I always end up typing “ls -ltrah”, which shows hidden files (among other things).
So, I ended up with this in my .vimrc:
The // at the end of each path is the clever bit - it ensures that vim creates a swap file name based on the entire path of the file (with directory separators converted to %) so that there’s not much chance of having swapfile names collide.
Make sure to run
mkdir -p ~/.vimswaps. Having /tmp as a fallback means that it’ll still work, but /tmp is usually insecure and you probably don’t want to pollute it with swap files as well!