Let's say there is a vimscript function that takes a dictionary as a parameter. In vimscript, it is called like this:

call Vote({'name':'Phil Collins', 'band':'Genesis'})

I'm interested in what that function call (not the function itself) looks like in lua. The following statements work, but I wonder if there's a better, more lua-like way.

vim.cmd("call Vote({'name':'Neil Peart', 'band':'Rush'})")
vim.cmd.call("Vote({'name':'Larnell Lewis', 'band':'Snarky Puppy'})")

:h vim.cmd() shows there is an args key that can be used. Let's try that. This works, but it's even messier:

vim.cmd.call {args={"Vote({'name':'Ringo Starr', 'band':'Beatles'})"} }

I'd like to split that long string into a function name and its parameter, reformatted as a lua array. This doesn't work:

vim.cmd.call {args={"Vote", {name='Joe Morello', band='Dave Brubeck Quartet'}}}
E5108: Error executing lua [string ":lua"]:1: Invalid command arg: expected valid type, got Dict
stack traceback:
        [C]: in function 'call'
        [string ":lua"]:1: in main chunk

which leads me to believe that args can only apply to call, and not also to the Vote function inside of call. Is my observation correct, or is there a way to do this that I'm not seeing?

1 Answer 1


My understanding is that vim.cmd.xxx is somehow equivalent the vim.cmd('xxx').

There are no specific specific support for vim.cmd.call.

What you try to achieve is probably best done using (vim.fn):

vim.fn["Vote"]({name='Phil Collins', band='Genesis'})
  • 1
    That works like a charm, Vivian. It makes sense now, but I hadn't expected vim.fn to support user-defined functions. Thanks!
    – Phil R
    Commented Apr 25 at 19:06
  • Thanks for the feedback :-) If you have nothing open in your question maybe could you accept one solution using the v button. It allow the question to rest :-) Commented Apr 25 at 21:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.