hgiesel
hgiesel

Reputation: 5648

How come you can't use arguments in autocmd

Let's say I have some function which puts me into Insert mode, and I want to add a cleanup function which gets called, once I leave Insert mode. I would do something like this:

function! s:Foo(arg)
    augroup cleanup_group
        autocmd!
        autocmd InsertLeave * call <sid>cleanup(a:arg)
    augroup END
    " ...
endfunction

How come I can't do this? Also I can't use a:arg inside of remaps, which I kinda get, but why is this also not possible? How are you supposed to do this otherwise?

Upvotes: 0

Views: 178

Answers (1)

Luc Hermitte
Luc Hermitte

Reputation: 32946

If you want to pass arg (from s:Foo), you can play with :exe instead.

Something like:

...
exe 'autocmd InsertLeave * call <sid>cleanup('.string(a:arg).')'
...

Upvotes: 1

Related Questions