Skip to content

Commit

Permalink
Add more keybindings to menu
Browse files Browse the repository at this point in the history
Resolves #583.
  • Loading branch information
marlonrichert committed May 18, 2023
1 parent 181d3eb commit eda36fc
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions scripts/.autocomplete.key-binding
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ zmodload zsh/complist
zmodload -F zsh/parameter p:funcstack p:functions
zmodload -F zsh/terminfo p:terminfo

local -Pa prefix=( '\e'{\[,O} )
typeset -ga _autocomplete__key_up=( ${^prefix}A )
typeset -ga _autocomplete__key_down=( ${^prefix}B )
typeset -ga _autocomplete__key_alt_up=( '\e'$^_autocomplete__key_up '\e[1;3A' )
typeset -ga _autocomplete__key_alt_down=( '\e'$^_autocomplete__key_down '\e[1;3B' )

.autocomplete.key-binding.precmd() {
emulate -L zsh
setopt $_autocomplete__func_opts[@]
Expand All @@ -12,23 +18,28 @@ zmodload -F zsh/terminfo p:terminfo
.autocomplete.key-binding.rebind main menu-expand-or-complete complete-word '\t'

local backtab=$terminfo[kcbt]
.autocomplete.key-binding.bound main "$backtab" undefined-key &&
.autocomplete.key-binding.bind main insert-unambiguous-or-complete "$backtab"
.autocomplete.key-binding.rebind main undefined-key insert-unambiguous-or-complete "$backtab"

.autocomplete.key-binding.bound main '\t' complete-word &&
.autocomplete.key-binding.bound main complete-word '\t' &&
.autocomplete.key-binding.bind-menu accept-line '\t'

.autocomplete.key-binding.bind main history-search-backward $_autocomplete__key_alt_up[@]
.autocomplete.key-binding.bind main menu-select $_autocomplete__key_alt_down[@]
.autocomplete.key-binding.bind main history-search-backward $_autocomplete__key_alt_up[@]
.autocomplete.key-binding.bind-menu vi-backward-blank-word $_autocomplete__key_alt_up[@]
.autocomplete.key-binding.bind main menu-select $_autocomplete__key_alt_down[@]
.autocomplete.key-binding.bind-menu vi-forward-blank-word $_autocomplete__key_alt_down[@]

.autocomplete.key-binding.rebind emacs history-search-backward history-search-backward '\ep'
.autocomplete.key-binding.bind-menu vi-backward-blank-word '\ep'
.autocomplete.key-binding.rebind emacs history-search-forward menu-select '\en'
.autocomplete.key-binding.bind-menu vi-forward-blank-word '\en'

.autocomplete.key-binding.rebind vicmd vi-rev-repeat-search history-search-backward 'N'
.autocomplete.key-binding.rebind vicmd vi-repeat-search menu-select 'n'

.autocomplete.key-binding.rebind emacs history-incremental-search-backward{,} '^R'
.autocomplete.key-binding.bind-menu history-incremental-search-backward '^R'
.autocomplete.key-binding.rebind emacs history-incremental-search-forward menu-search '^S'
.autocomplete.key-binding.bind-menu history-incremental-search-backward '^S'

.autocomplete.key-binding.rebind vicmd {vi-history,history-incremental}-search-backward '/'
.autocomplete.key-binding.rebind vicmd vi-history-search-forward menu-search '?'
Expand All @@ -49,14 +60,14 @@ zmodload -F zsh/terminfo p:terminfo
}

.autocomplete.key-binding.bound() {
[[ $( builtin bindkey -M "$1" "$2" ) == \"[^[:space:]]##\"\ $3 ]]
[[ $( builtin bindkey -M "$1" "$3" ) == \"[^[:space:]]##\"\ $2 ]]
}

.autocomplete.key-binding.rebind() {
local -P keymap=$1 old=$2 new=$3 key=
shift 3
for key; do
.autocomplete.key-binding.bound "$keymap" "$key" "$old" &&
.autocomplete.key-binding.bound "$keymap" "$old" "$key" &&
builtin bindkey -M "$keymap" "$key" "$new"
done
}
Expand All @@ -66,18 +77,15 @@ zmodload -F zsh/terminfo p:terminfo
builtin bindkey -M "$1" -r "$2"
}


local -Pa prefix=( '\e'{\[,O} )
typeset -ga _autocomplete__key_up=( ${^prefix}A )
typeset -ga _autocomplete__key_down=( ${^prefix}B )
typeset -ga _autocomplete__key_alt_up=( '\e'$^_autocomplete__key_up '\e[1;3A' )
typeset -ga _autocomplete__key_alt_down=( '\e'$^_autocomplete__key_down '\e[1;3B' )

.autocomplete.key-binding.bind main up-line-or-search $_autocomplete__key_up[@]
.autocomplete.key-binding.bind main down-line-or-select $_autocomplete__key_down[@]
.autocomplete.key-binding.bind main up-line-or-search $_autocomplete__key_up[@]
.autocomplete.key-binding.bind-menu up-history $_autocomplete__key_up[@]
.autocomplete.key-binding.bind main down-line-or-select $_autocomplete__key_down[@]
.autocomplete.key-binding.bind-menu down-history $_autocomplete__key_down[@]

.autocomplete.key-binding.rebind emacs up-line-or-{history,search} '^P'
.autocomplete.key-binding.bind-menu up-history '^P'
.autocomplete.key-binding.rebind emacs down-line-or-{history,select} '^N'
.autocomplete.key-binding.bind-menu down-history '^N'

.autocomplete.key-binding.rebind vicmd up-line-or-{history,search} 'k'
.autocomplete.key-binding.rebind vicmd down-line-or-{history,select} 'j'
Expand All @@ -89,11 +97,6 @@ local -Pa menukeys=(
"$terminfo[knp]" forward-word
'^[v' backward-word
'^V' forward-word
'^R' history-incremental-search-backward
'^S' history-incremental-search-forward
)
builtin bindkey -M isearch "$menukeys[@]"
builtin bindkey -M menuselect "$menukeys[@]"

.autocomplete.key-binding.bind-menu vi-backward-blank-word $_autocomplete__key_alt_up[@]
.autocomplete.key-binding.bind-menu vi-forward-blank-word $_autocomplete__key_alt_down[@]

0 comments on commit eda36fc

Please sign in to comment.