如何更改 Vim 中 swp 文件的文件夹路径

我在远程服务器上做一个项目。我不希望服务器上有交换文件。我希望 Vim (当然还有 gVim)的所有交换文件都保存在指定的目录中。我怎么能这么做?

48448 次浏览

You might want to consider setting the backupdir options as well:

set backupdir=Z:\backups

That makes vim store backups in a specific location rather than in the current directory.

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.