Call a function in Vim’s `autocmd` command

匿名 (未验证) 提交于 2019-12-03 00:54:02

问题:

I want to use the expand function in an autocmd. In particular, I am adapting a tip by Paul Biggar and I wanted to use the following auto command in my .gvimrc:

autocmd FileType tex set makeprg=rubber-info\ expand("%:t:r").log 

tex file, the makeprg variable is set to the value of rubber-info filename.log where filename is the name of the TeX file without its file extension.

How can I accomplish this?

回答1:

You can try something like this; untested, may not be exactly right, but using exe is generally how I get around this kind of problem.

autocmd FileType tex exe "set makeprg=rubber-info\\ " . expand("%:t:r") . ".log" 


回答2:

The alternative is to set makeprg using &l:makeprg:

autocmd FileType tex let &l:makeprg = "rubber-info " . expand("%:t:r") . ".log" 

See :help let-& if you want more information about settings options using :let.



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