最近我试图切换到在工作目录以外的目录中备份和交换文件。使用swp文件,您可以在路径末尾添加双斜杠:
+
但是,这不适用于set directory=~/.vim/swp//
。然而,我找到了一个解决方法的答案:
backupdir
关于此解决方法,我有几个问题:
autocmd BufWritePost * :execute ':w! ' ."$HOME/.vim/backups/" . escape(substitute(expand('%:p'), "/", "%", "g"), "%")
中保存文件,但 是如何执行此操作的?$HOME/.vim/backups/[filename with path]
(差异为〜结尾)由于
答案 0 :(得分:1)
我的解决方法是
" this is a default. to be updated per file type
autocmd BufNewFile,BufNew,BufRead * let b:buDir = "/work/BACKUP/vimBackups/all/"
然后,在每个文件类型的基础上我做了
let b:buDir = "/work/BACKUP/vimBackups/text/"
或
let b:buDir = "/work/BACKUP/vimBackups/coding/"
然后,我在每个出口处调用我的备份
" the backup command
" currently, overwrite whatever is there: a new file will be made each second
" if necessary
autocmd VimLeavePre,BufWritePre * silent execute ":write! >> ".b:buDir."vim_bu_".strftime('%Y-%b-%d__%H:%M:%S')."_".b:buFilename.".bu.txt "
然后,在每日清理脚本中,从cron(anacron)运行,我删除了我的旧备份
# vim backups older than a month old
find $VIM_BU_DIR -not -newerat "1 month ago" -delete ;