Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
93 views
in Technique[技术] by (71.8m points)

swapfile - How to change the folder path for swp files in Vim

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...