Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zsh completion: How to find the function that is used for completions with a specific command?

I am writing a zsh completion function for a shell script/program I wrote. At some point in the completion process I want to use the completion function of another command to handle the rest of the completion.

How can I find out what the completion function for a specific command is called? How can I look up the existing compdef assignments in my shell?

Background

My program wraps nvim and there is no _nvim function in my shell which I would have guessed would be the completion function. So I assume the completion function that nvim uses is actually _vim but this question is more general in order to learn.

like image 282
Lucas Avatar asked Nov 30 '25 08:11

Lucas


1 Answers

Type the command plus a space and then press CtrlX followed by H to the run the _complete_help widget. For example:

% nvim # press ^Xh here
tags in context :completion::complete:nvim::
    argument-rest options  (_arguments _vim)
tags in context :completion::complete:nvim:argument-rest:
    globbed-files  (_files _vim_files _arguments _vim)

This tells you that for arguments to command nvim , the completion system will call _vim, which then calls _arguments, which adds argument-rest and options completions. Then, _arguments calls _vim_files, which calls _files, which adds globbed-files completions.

Alternatively, if you're interested in only the top-level completion function set for a particular command, do this:

% print $_comps[nvim]
_vim
like image 88
Marlon Richert Avatar answered Dec 02 '25 03:12

Marlon Richert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!