Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the folder path for swp files in Vim

Tags:

vim

swapfile

I'm working at a project on a remote server. I don't want to have the swap files on the server. I would like all swap files for Vim (and, of course, gVim) to be saved on the specified directory. How could I do that?

like image 230
sica07 Avatar asked Oct 28 '09 10:10

sica07


People also ask

Where does Vim store SWP files?

swp is a swap file, containing the unsaved changes. While editing a file, you can see which swap file is being used by entering :sw . The location of this file is set with directory option. The default value is .,~/tmp,/var/tmp,/tmp .

Where are swap files stored?

By default, the swap file is created in the same location as the virtual machine's configuration file, which may either be on a VMFS datastore, a vSAN datastore or a VMware vSphere® Virtual VolumesTM datastore. On a vSAN datastore or a vVols datastore, the swap file is created as a separate vSAN or vVols object.


1 Answers

You can set the directory option to the location that you want vim to store its swap files, e.g.:

 mkdir -p $HOME/.vim/swapfiles  # this dir must exist vi does not create it  " $HOME/.vimrc :set directory=$HOME/.vim/swapfiles// 

I use trailing double path separators because, from the help docs:

For Unix and Win32, if a directory ends in two path separators "//" or "\\", the swap file name will be built from the complete path to the file with all path separators substituted to percent '%' signs. This will ensure file name uniqueness in the preserve directory.

like image 75
maerics Avatar answered Sep 21 '22 22:09

maerics