Vim: Combining autocmd?

孤街浪徒 提交于 2020-01-01 05:21:07

问题


I need to do the logical-and of two autocmd events in vim. Basically, the command has to run on an InsertLeave when the FileType is tex. It seems like this should work (in a .vimrc):

autocmd FileType tex :autocmd InsertLeave :w

But it doesn't. The nested option doesn't seem to help either, even though the manual indicates it should.

Its easy to do a logical-OR:

autocmd BufEnter,BufLeave ...

it mustn't be too hard to do a logical-AND.


回答1:


I have a correction to @Eevee answer: to make autocommand work for one buffer only, you should use

augroup TexAutoWrite
    autocmd FileType tex :autocmd! TexAutoWrite InsertLeave <buffer> :update
augroup END

, see `:h autocmd-buflocal.




回答2:


InsertLeave still needs a parameter.

This works for me:

autocmd FileType tex :autocmd InsertLeave * :w

Note that this behavior will remain if you later edit a non-tex file in the same buffer. I'm not sure if there's a simple way to remove it when editing anything but a certain type of file.




回答3:


You can use the pattern option of the autocmnd.

autocmd InsertLeave *.tex w


来源:https://stackoverflow.com/questions/1313171/vim-combining-autocmd

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!