是否可以使用变量或列表将模式传递给vim的autocmd?
以下是一个例子:
" Automatically source .vimrc if there have been any changes
let candidates = [ ".vimrc", "_vimrc", "vimrc", ".gvimrc", "_gvimrc", "gvimrc" ]
augroup AutoSourceVimrc
autocmd!
autocmd BufWritePost candidates so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif
augroup END
不幸的是,上面的例子不起作用。
答案 0 :(得分:2)
以下是您的命令的更简单版本:
augroup AutoSourceVimrc
autocmd!
autocmd BufWritePost *vimrc execute "source " . expand("<afile>")
augroup END