Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I pass varargs to another function in vimscript?

I want to write a wrapper to a plugin's function, but it uses varargs (...). How can I pass the same arguments my function receives to the plugin's function?

Example:

function! PluginInterface(...)
    for i in a:000
        echo i
    endfor
endfunction

function! MyInterface(...)
    echo a:1 . ' is great'
    call PluginInterface(a:000)
endfunction

echo '>> Their call'
call PluginInterface('hello', 'world')
echo '>> My call'
call MyInterface('hello', 'world')
like image 231
idbrii Avatar asked Jul 28 '12 17:07

idbrii


1 Answers

Instead of calling the function directly (call PluginInterface(a:000)), use call():

call call("PluginInterface", a:000)
call call(function("PluginInterface"), a:000)

(That looks strange, but call() is a function so you still have to prefix it with :call or let x = or something that accept an expr.)

See :help call().

like image 79
idbrii Avatar answered Sep 24 '22 10:09

idbrii