Call a function in Vim’s `autocmd` command
Asked Answered
A

2

4

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

– 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?

Appetence answered 19/11, 2009 at 20:36 Comment(0)
C
3

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"
Christy answered 19/11, 2009 at 20:50 Comment(0)
E
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.

Enterotomy answered 20/11, 2009 at 0:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.