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?

  • You can get quite deep into customizing zsh's behavior. What should happen exactly? At the moment this question reads like you want the choices to be listed for every key press after the initial TAB, but that won't actually complete anything. Should every key press behave as if it was followed by a TAB? Bear in mind that this would mean quite a bit of backspacing for unintended completions. – peth Mar 5 '12 at 9:34
  • @user112553 The first option: In that sense, it shouldn't actually behave like a repeated TAB. I just want the suggestion list to dynamically adjust. – F30 Mar 5 '12 at 14:13

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):

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.

| improve this answer | |

I created a plugin that does exactly what you're asking for: https://github.com/marlonrichert/zsh-autocomplete

It automatically lists completion choices as you type, without inserting them, and without needing to press any additional keyboard shortcuts. No need to press ctrl-x+i or ctrl-d or anything like that. It automatically lists everything, all the time, as long as it fits on screen.

Then, press Tab to insert the top match or press Down to start menu selection.

You can watch a demo on the page above to see if it’s what you want. 🙂

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.