1

Is it possible to programmatically get a command's definition so that its completion function can be called manually? Alternatively, is it possible to define a command such that the first argument is used to determine the completion function to use?

What I'm trying to do:

I have some commands (Cmd1, Cmd2, etc.) that are defined with their own completion function using the -complete flag. The completion function might be a custom function or may be one of the built in options like file or shellcmd.

I'm now creating a "wrapper command" (WrapperCmd) that would take in a command name and that command's arguments. So, invoking things would be something like this:

:WrapperCmd Cmd1 cmd1-argument

After typing :WrapperCmd Cmd1 the completion options should be the ones relevant to Cmd1 and after typing :WrapperCmd Cmd2 the completion options should be the ones relevant to Cmd2.

P.S.

I really struggled to come up with a clear and succinct way of phrasing the title (perhaps an indication that I'm trying to get too weird with things). Suggestions for improving it are more than welcome.

2
  • 1
    Assuming you have some logic for WrapperCmd's -complete=function to examine current arguments, have a look at getcompletion()
    – D. Ben Knoble
    Sep 25, 2023 at 19:03
  • Some very brief testing seems to suggest this is exactly what I'm looking for. Thanks! If you care to turn this into an answer, I'll mark it as accepted once I get things working.
    – Pak
    Sep 25, 2023 at 19:21

1 Answer 1

1

Light on details, but: you can call getcompletion() to find out how Vim would complete for certain strings. So if you can examine the command line and pass sensible values to getcompletion() in WrapperCmd's completion function, you're probably in buisinesss.

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.