Dynamically update completion list in zsh

autocompletezsh

I find zsh's result lists for Tab completion quite useful, however I'd like to tweak their behaviour a bit:

They should appear when I Tab for the first time and afterwards dynamically update with every new letter added. The default behaviour is that the suggestions are only re-evaluated when you Tab again, I want to save this repeated keypress. (Update: But only list the possible completions, it shouldn't automatically modify my actual prompt line even if there is only one option left.)

Is there any way to achieve such behaviour?

Best Answer

One way which might offer the solution you want, is incremental-complete-word:

zle -N incremental-complete-word
bindkey '^Xi' incremental-complete-word

This loads the funtion and binds it to Ctrl-X i. Now you can try it:

> k^Xi
incremental (complete): -no prefix-

In this example the letter k was typed, followed by Control-X i.

> kil
incremental (complete): kill       

I typed il and now there was one possible completion (kill). One could accept that and press enter.

> kill^D
incremental (complete): -no prefix-
- external command -
kill      killall   killall5

By typing Ctrl-D the zsh shows possible completions.

From zshcontrib(1):

incremental-complete-word
This allows incremental completion of a word. After starting this command, a list of completion choices can be shown after every character you type, which you can delete with ^H or DEL. Pressing return accepts the completion so far and returns you to normal editing (that is, the command line is not immediately executed). You can hit TAB to do normal completion, ^G to abort back to the state when you started, and ^D to list the matches.