Call a function with list or splat arguments

vim

Solution

The equivalent of JavaScript's `apply()` is `call()` in Vimscript:

function! hello(...)
    call call('run_hello', ['foo'] + a:000)
endfunction

This is no typo: You `:call` the function named `call()`.

Problem

Is there a way to call a vim function with a list of arguments. My list of arguments is coming from a optional splat arguments in another function, and I need a way to pass these arguments to the target function. The target function is, ``` function! run_hello(cmd, ...) echo 'run_hello' echo a:cmd echo a:000 endfunction ``` The function that will call `run_hello` is, ``` function! hello(...) call run_hello('foo', the splats here) endfunction ``` It will be called like so, with different arguments. ``` call hello('lorem', 'ipsum', 'dolor') ``` I am currently using `hello(arglist)` and passing the `a:000` list forward. But I would like to know if it is possible to call a function with a list as arguments, that then become it's regular argument list. Something like JavaScript's, ``` foo.apply(this, ['a', 'b', 'c'] ``` Thanks.

Original source