Skip to content

How to bind keys only for History Menu? #678

Answered by JerryZhongJ
JerryZhongJ asked this question in Q&A
Discussion options

You must be logged in to vote

I figure out a solution, that is adding a wrapper to the two widgets, history-search and complete-word. The wrappers call bindkey every time the widgets are called.

I add this to my .zshrc:

wrap(){
  functions[${1}:old]="$(
      unfunction ${1} 2> /dev/null
      builtin autoload +X -Uz ~autocomplete/Functions/Widgets/${1}
      print -r -- "$functions[${1}]"
  )"
  eval "${1}(){
    bindkey -M menuselect $terminfo[kcub1] ${2}
    bindkey -M menuselect $terminfo[kcuf1] ${3}
    bindkey -M menuselect '\r' ${4}
    ${1}:old \$@
  }"
}
wrap .autocomplete__history-search__completion-widget .backward-char .forward-char .accept-line
wrap .autocomplete__complete-word__completion-widget backward…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@marlonrichert
Comment options

@JerryZhongJ
Comment options

Answer selected by JerryZhongJ
Comment options

You must be logged in to vote
1 reply
@DreadPirateFlint
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants