1

When I am using zsh (default installation of oh-my-zsh) and press Tab it auto-completes the path which is very useful.

If there is only one candidate the auto-completion system just add the candidate to the path you're currently typing, as expected!

But if there are more than one candidate it displays a list below the PS for you to see, from here you have two choices:

  1. You see one item in the list that matches your intention, you start typing the first letters and tab again to autocomplete the full word.

  2. You tab directly after the list appears and then you can use the navigation keybindings to select an item in the list and then press enter to append the selected item in the current path you're typing.

In the second case you've pressed Tab two times in a row, the second Tab to enter the navigation mode.

Is there a way to tell zsh to directly enter the navigation list, in other words to highlight the first item if there is a list of choices?

2
  • 1
    Possibly just a matter of doing set -o menucomplete. See info zsh menucomplete for details. Commented Jan 24, 2020 at 17:32
  • @StéphaneChazelas merci
    – vdegenne
    Commented Jan 24, 2020 at 17:40

2 Answers 2

1

Add the following to your .zshrc file:

zstyle ':completion:::::default' menu yes select
  • A zstyle statement is kind of like a CSS rule, with the first argument functioning similar to a CSS selector (or namespace), the second argument being like a CSS property, and all further arguments being values. To override OMZ's zstyle ':completion:*:*:*:*:*' menu select, like in CSS, we need to either use a "heavier" selector or use the same selector but set it later (the latter of which completely replaces the existing rule). Here, I've made our selector heavier by adding default to it. We can omit the *s, because those parts of the selector are always empty for the default tag.
  • When select is one of the values assigned to the menu attribute, it tells the completion systems to always use menu selection when using menu completion. With that last clause lies a problem in OMZ’s implementation: Even though OMZ's rule tells Zsh to always use selection when using the menu, it does not tell Zsh to always use the menu. To always start menu completion on the first try, we need to add yes.

Alternatively, if you get tired of trying to configure Zsh's completion system, try my Zsh Autocomplete plugin.

0

There is a pretty simple way to achieve this. I don't know oh-my-zsh, but I know this issue.
It's as simple as including zstyle '*' single-ignored complete somewhere in your shell config, preferably after your oh-my-zsh config gets loded. Hope this helps!

1
  • I tried to include that in my ~/.zshrc after the oh-my-zsh sourcing but it has no effect even I restart the shell. Any others ideas ? (thx btw)
    – vdegenne
    Commented Jan 24, 2020 at 11:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .