简体   繁体   中英

Is there a way to check if the tab completion menu is open in ZSH

Is there a way to check if the tab completion menu is open in ZSH?

I am asking this question because I want to bind the space key to accept-search so that I can accept completion with the space key, but I want to do it in a way that doesn't interfere with the default behaviour of the space key (inserting the space character). Also, I want this because I don't like that when I close the completion menu with space it inserts an space.

Someone in reddit helped me with this snippet, but I need a way to check if the autocompletion menu is open or not.

function space-or-accept-suggestion() {
  if <INSERT WAY TO CHECK IF AUTOCOMPLETION MENU IS OPEN>; then
    zle accept-search
  else
    zle self-insert
  fi
}

zle -N space-or-accept-suggestion
bindkey -M emacs ' ' space-or-accept-suggestion

You don't need to check that. Just use this:

zmodload zsh/complist
bindkey -M menuselect ' ' accept-search

More info can be found here: http://zsh.sourceforge.net/Doc/Release/Zsh-Modules.html#Menu-selection

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM