Skip to content
Advertisement

What is the line to add to vimrc for storing .swp files in /tmp on Ubuntu

I feel like I’ve literally tried everything, but no matter what I add to vimrc, I can’t get it to store its annoying .swp files in /tmp. I’m using Ubuntu 16.04. I’ve obviously looked up this issue extensively, but again, no command I enter seems to work. I always end up with:

E510: Can't make backup file
(add ! to override)

Things I’ve tried:

set backupdir=$~/tmp//
set directory=$~/tmp//
set backupdir=~/tmp//
set backupdir=$HOME~/tmp//
set backupdir=/tmp//

I mean you name it, I’ve tried it. So, explicitly, what is the exact code I need to type in vimrc to make it so vim saves it’s .swp files in my temporary folder, instead of cluttering my workspace?

Thank you.

Advertisement

Answer

Adding the following line to my ~/.vimrc puts .swp files for currently open buffers under /tmp

set directory=/tmp

If you’ve tried this without issues are you able to verify that vim is reading your vimrc at all?

Advertisement