How to change the folder path for swp files in Vim

让人想犯罪 __ 提交于 2019-12-03 02:55:20

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/1636297/how-to-change-the-folder-path-for-swp-files-in-vim

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!