If you check the help for :command-completion, there is a line that reads:

-complete=lua       Lua expression

But it does not give further instructions about how to use it, or how to provide a Lua expression. Is it supposed to work like custom,function? Can I inline a Lua expression somehow? Does it do something else?

1 Answer 1


Obviously, this means that you can complete a Lua variable name (including variables of "function" type).

Or, if you prefer, "tab" completes from a keys list of a Lua table you are currently referencing (starting from the globals _G table assumed by default).

  • 1
    Frankly I'm not sure it's obvious at all. Similar lines like -complete=custom,{func} custom completion, defined via {func} and -complete=var user variables are either not a variable name, or indicate where a variable should be and what it is, etc. The quoted line in the OP is vague at best.
    – D. Ben Knoble
    Commented Jun 13, 2022 at 22:07
  • @D.BenKnoble There are "var" and "expression" that complete in VimScript variables and both var/funcs names respectively. In Lua all functions are variables by definition, so there's only a single completion "lua" instead of two. If you believe there's a need for better explanation in docs, you can propose a PR to Neovim project.
    – Matt
    Commented Jun 14, 2022 at 4:37
  • 2
    I see now—I think the misunderstanding you are pointing to in your answer was itself unclear. It seems you mean to say something like "-complete=lua does not offer a way to use lua for completion (see -complete=custom). Instead, it completes the names of lua variables, much like how -complete=var completes vimscript variables."
    – D. Ben Knoble
    Commented Jun 14, 2022 at 13:01
  • @D.BenKnoble I'm probably very bad in explaining in foreign language, as this is exactly what I'm trying to explain for a few days. -complete=lua completes Lua variable names. While custom completion in Lua is as simple as -complete=custom,v:lua.MyLuaCompletionFunc. So there's no need to re-invent custom completion for Lua specifically. What makes people even consider this?
    – Matt
    Commented Jun 14, 2022 at 14:48
  • Like I said, I think I'm following now. I don't know the reason for the OP's confusion, but mine was something like "everyone wants to put everything in Lua [this seems misguided], so having a completion that uses lua specifically might make sense, and this is the only part of the docs that mention it." That said, I don't use NeoVim, so I was also probably led astray by trying to compare the quoted docs with the vim docs :P
    – D. Ben Knoble
    Commented Jun 14, 2022 at 15:50

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.