Navigate zsh’s tab-completion menu with vi-like hjkl keys

autocompleteline-editorzsh

I use zsh's menu-based tab completion. I press Tab once, and a list of possible completions appears. If I press Tab again, I can navigate this list with the arrow keys. However, is it possible to navigate them with the vi-like H, J, K, L keys instead?

I use emacs mode for command-line input, with bindkey -e in ~/.zshrc. I also use zim with zsh. If relevant, the commands that specify the tab-completion system are here.

Best Answer

Yes, you can by enabling menu select:

zstyle ':completion:*' menu select
zmodload zsh/complist
...
# use the vi navigation keys in menu completion
bindkey -M menuselect 'h' vi-backward-char
bindkey -M menuselect 'k' vi-up-line-or-history
bindkey -M menuselect 'l' vi-forward-char
bindkey -M menuselect 'j' vi-down-line-or-history