In zsh, if I type vim *.txt then Tab, it expands to vim f1.txt f2.txt f3.txt.

How can I make it show a completion menu listing files matching the pattern, so I can select a single file?

% PS1='%% ' exec zsh -f
% autoload -U compinit && compinit
% touch aa ab ac ad
% vim a*

Will cycle through the options; and then for a menu (on, like, everything)

% zstyle ':completion*:default' menu 'select=0'
% vim a*

For more information see zshoptions(1) and the "From Bash to Z Shell" book for slightly readable docs on the completion system.

Menu completion on demand would require a custom widget:

function blaah {
  local revert
  if [[ $options[(k)globcomplete] = off ]]; then
    setopt globcomplete
  zle menu-expand-or-complete
  if [[ $revert -eq 1 ]]; then
    unsetopt globcomplete
zle -N blaah

# or perhaps additionally 'vicmd' or instead 'emacs', depending
binkey -M viins "^W" blaah
  • Thanks! setopt GLOB_COMPLETE works; but it is globally. Is there a bindkey to do "menu complete" (or "expand") on demand? – aggu Apr 21 '16 at 3:02
  • @aggu you'll need a widget, I believe – thrig Apr 21 '16 at 14:36
  • how do I "see zshoptions(1)"? – cambunctious Oct 29 '18 at 23:38
  • 1
    @cambunctious manpage(section) translates to the man section manpage command so man 1 zshoptions – thrig Oct 30 '18 at 13:40

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.