更改Vim交换/备份/撤消文件名 [英] Change Vim swap/backup/undo file name
问题描述
是否可以更改Vim命名其交换/备份/撤消文件的方式?
Is it possible to change the way Vim names its swap/backup/undo files?
为避免混乱,我在~/.vimrc
中设置了将这些文件转储到~/.vim/tmp/{swap,backup,undo}
中的选项.但是,由于我经常用相同的名称编辑不同目录中的文件,所以我常常会遇到很多其他无法区分的文件,并且Vim有时很难恢复.
To avoid clutter, I've set options in my ~/.vimrc
to dump these files in ~/.vim/tmp/{swap,backup,undo}
; however, as I routinely edit files in different directories with the same name, I often end up with lots of otherwise indistinguishable files and Vim sometimes has trouble recovering.
理想情况下,我想对所有这些辅助文件使用永久撤消(%path%to%file.undo
)的命名方案.没有明显的方法来设置它,但是可以使用Buf{Read,Write}
宏吗?
Ideally, I'd like to use the naming scheme that the persistent undo has (%path%to%file.undo
) for all these auxiliary files; there's no obvious way to set it, but can it be done with Buf{Read,Write}
macros?
推荐答案
我在我的.vimrc
中有此名称,它使用完全路径名和百分号来命名交换文件,就像您描述的那样:
I have this in my .vimrc
and it names the swap files with full path names and percent signs just as you describe:
" Store swap files in fixed location, not current directory.
set dir=~/.vimswap//,/var/tmp//,/tmp//,.
键是目录末尾的//
.请参见:help dir
的注释:
The key is the //
at the end of the directories. See this note from :help dir
:
- 对于Unix和Win32,如果目录以两个路径分隔符结尾
"//"
或"\\"
,交换文件名将从完整路径构建到 所有路径分隔符都替换为百分号%"的文件. 这样可以确保保留目录中文件名的唯一性.
- 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.
这篇关于更改Vim交换/备份/撤消文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!