vim - 更改 Vim 交换/备份/撤消文件名

标签 vim swapfile

是否可以更改 Vim 命名其交换/备份/撤消文件的方式?

为了避免困惑,我在 ~/.vimrc 中设置了选项,将这些文件转储到 ~/.vim/tmp/{swap,backup,undo} >;然而,当我经常编辑不同目录中具有相同名称的文件时,我经常会得到许多无法区分的文件,并且 Vim 有时难以恢复。

理想情况下,我想对所有这些辅助文件使用持久撤消的命名方案 (%path%to%file.undo);没有明显的方法来设置它,但是可以使用 Buf{Read,Write} 宏来完成吗?

最佳答案

我的 .vimrc 中有这个,它用完整路径名和百分号命名交换文件,正如您所描述的那样:

" Store swap files in fixed location, not current directory.
set dir=~/.vimswap//,/var/tmp//,/tmp//,.

关键是目录末尾的//。请参阅 :help dir 中的注释:

  • 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 - 更改 Vim 交换/备份/撤消文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4331776/

相关文章:

vim - 如何从 vim 重命名文件名?

vim - 如何在 Vim 自动完成后自动删除预览窗口?

MongoDB 内存不足

linux - 从命令行打开文件时使 vim 遵循符号链接(symbolic link)

regex - 如何在 VsCode Vim 中替换换行符

linux - 交换文件在重启后恢复到原始大小

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

vim - 如何在 VIM 中走高/走低并保持在同一列?

c++ - 如果内存有限,new 会自动使用 swap 吗?