在Vim的`autocmd`命令中调用一个函数 [英] Call a function in Vim’s `autocmd` command
问题描述
我想在 autocmd
中使用 expand
函数。特别是,我正在调整Paul Biggar的小费,我想要在我的 .gvimrc
中使用以下自动命令:
$ b
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
文件时, makeprg
变量被设置为值 rubber-info filename.log
其中 filename
是没有文件扩展名的TeX文件的名称。
– Which of course doesn’t work. So what I actually want this to mean is that upon opening a 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?
推荐答案
未经测试,可能不完全正确,但使用 exe
通常是我如何解决这类问题的方法。
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"
这篇关于在Vim的`autocmd`命令中调用一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!