20

When zsh shows you a menu of possible completions, I'd like it to let me use shift-tab to access previous completion entries--is there an option that controls what key is used to access previous completion entries?

And if so, what would I need to add to my ~/.zshrc file in order to set it up.

If it makes any difference, I currently can navigate through a completion-menu using the arrow-keys, but I dislike doing this since the arrow-keys feel out of place and awkward to use.

2 Answers 2

23

you want to bind the editor command reverse-menu-complete to the menuselect keymap.

bindkey -M menuselect '^[[Z' reverse-menu-complete

I am not sure how portable the escape sequence ^[[Z is, so you may want to check terminfo(5) to see if there is a way of using the $terminfo array to correctly bind it.

Note that the menuselect keymap is available after you load the zsh/complist module. If you've configured the completion system with compinstall, that module is generally automatically loaded the first time you complete something. To be able to add that binding to your ~/.zshrc, you need to load the module manually there first with:

zmodload zsh/complist
3
  • ^[[Z is shift-tab on my computer too, so no worries about it not being portable; thank you. :) Jul 30, 2013 at 4:36
  • 4
    I get the following error when I invoke zsh after adding the bindkey line to my ~/.zshrc file: ~/.zshrc:bindkey:190: no such keymap `menuselect' Jul 30, 2013 at 4:39
  • 3
    That would be "${terminfo[kcbt]}". Apr 11, 2016 at 0:09
7

The accepted answer practically doesn't work for me. zsh crashes if I try to use menu completion (set zstyle ':completion:*' menu select') with zmodload zsh/complist in .zshrc:

name clash when adding ZLE function `menu-select'

If you don't set zstyle ':completion:* menu select then it doesn't do anything (as the completion doesn't use the menu), or if you don't include the zmodload... then the setting doesn't work.

The correct, uncomplicated setting is:

bindkey '^[[Z' reverse-menu-complete

This works both if you enable the completion menu and if you 'inline' completion suggestions!

You must log in to answer this question.

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