I am write a plugin for neovim in python using this client and I looking for a way to offer completion when executing a command. I have look at the following example to structure my plugin. As an example, I could have a command Foo and when you call it the first time:

Foo bar

the second time you could autocomplete:

Foo b<tab> -> Foo bar

as an example my this is what my plugin look like in my ~/.config/nvim/rplugin/python3/my_plugin.py:

import neovim

class MyPlugin(object):
    def __init__(self, vim):
        self.vim = vim
        self.current_args = []

    @neovim.command("Cmd", range="", nargs="*", sync=True)
    def CmdHandler(self, args, range):
        if args[0] not in self.current_args:

And I guess I would need to write a function for the completion for the command?

def MyCompletionFunction(self, args):

and set my function as completion function for my command. any help appreciated

1 Answer 1


First of all, when you define a new command in the way I do, a user-command, you can specify in which way the command will be autocompleted (command-completion) and there's a lot of choices. So the way I did it is with a customlist function as follow:

class MyPlugin(object):

    def __init__(self, vim):
        self.vim = vim
        self.values = []

    @neovim.command("Cmd", complete='customlist,MyFunc', range="", nargs="1", sync=True)
    def Cmd(self, args, range):
        new_value = args[0]

    @neovim.function("MyFunc", sync=True)
    def MyFunc(self, *args, **kwargs):
        return self.values

so each time I exec the command

:Cmd value1

next time, I can

:Cmd va<Tab>  -> :Cmd value1

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.