20

Currently ZSH displays a menu when I first hit tab and the completion is ambiguous. So, if I have 'cd ' in the command prompt and I hit tab, it will show the different available completions. If I hit tab again, it will select the first available completion.

I would like to merge these two steps into a single press of the tab key. So, if I'm at 'cd ' and I tab, I would like ZSH to insert the first available match (when ambiguous) and display the menu, which I can then tab through if the first match wasn't the directory I had in mind.

The ZSH setup tool put this in my .zshrc, in case any of this is affecting the behavior of my shell:

zstyle ':completion:*' completer _expand _complete _ignored
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' matcher-list 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' '' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}'
zstyle ':completion:*' menu select=5
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle :compinstall filename '/home/robb/.zshrc'
Gilles 'SO- stop being evil'
865k204 gold badges1.8k silver badges2.3k bronze badges
asked Apr 23, 2011 at 16:49
1
  • Add this line to your ~/.zshrc: setopt menu_complete See man zshoptions for details. Commented Apr 23, 2011 at 17:06

4 Answers 4

21

Add this line to your ~/.zshrc:

setopt menu_complete

See man zshoptions for details.

answered Apr 23, 2011 at 17:06
2
  • Can I make it autocomplete the first file first (if there is a matching file and directory) Commented Jun 18, 2023 at 21:32
  • This won't work when using Zsh's new completion system, which he clearly is, since zstyle config doesn't work the old completion system. Commented May 14 at 7:12
1

if original question didn't have this in their .zshrc but if you went through the compinstall process, check to make sure that you don't have "_list" on the completer options:

zstyle ':completion:*' completer _expand _complete _ignored _correct _approximate _prefix

With _list, you only get a list of possible completions with the first tab-completion request, and it overrides some solutions.

answered Sep 19, 2021 at 3:38
1

Make sure you don't have _list set:

I had:

zstyle ':completion:*' completer _list _expand _complete _ignored _match _correct _approximate _prefix

Removing _list had it expand immediately.

answered Jan 13, 2022 at 10:07
0

From Zsh's documentation on the menu setting:

If the value contains the string ‘select’, menu selection will be started unconditionally.

In the form ‘select=num’, menu selection will only be started if there are at least num matches. If the values for more than one tag provide a number, the smallest number is taken.

So, change this line

zstyle ':completion:*' menu select=5

to this

zstyle ':completion:*' menu select
answered May 14 at 7:11

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.