81 lines
2.6 KiB
Bash
81 lines
2.6 KiB
Bash
# Keybindings - from zshwiki.org
|
|
|
|
# create a zkbd compatible hash;
|
|
# to add other keys to this hash, see: man 5 terminfo
|
|
typeset -A key
|
|
|
|
key[Home]=${terminfo[khome]}
|
|
key[End]=${terminfo[kend]}
|
|
key[Insert]=${terminfo[kich1]}
|
|
key[Delete]=${terminfo[kdch1]}
|
|
key[Up]=${terminfo[kcuu1]}
|
|
key[Down]=${terminfo[kcud1]}
|
|
key[Left]=${terminfo[kcub1]}
|
|
key[Right]=${terminfo[kcuf1]}
|
|
key[PageUp]=${terminfo[kpp]}
|
|
key[PageDown]=${terminfo[knp]}
|
|
key[Backspace]=${terminfo[kbs]}
|
|
|
|
# setup key accordingly
|
|
[[ -n "${key[Home]}" ]] && bindkey "${key[Home]}" beginning-of-line
|
|
[[ -n "${key[End]}" ]] && bindkey "${key[End]}" end-of-line
|
|
[[ -n "${key[Insert]}" ]] && bindkey "${key[Insert]}" overwrite-mode
|
|
[[ -n "${key[Delete]}" ]] && bindkey "${key[Delete]}" delete-char
|
|
[[ -n "${key[Up]}" ]] && bindkey "${key[Up]}" up-line-or-history
|
|
[[ -n "${key[Down]}" ]] && bindkey "${key[Down]}" down-line-or-history
|
|
[[ -n "${key[Left]}" ]] && bindkey "${key[Left]}" backward-char
|
|
[[ -n "${key[Right]}" ]] && bindkey "${key[Right]}" forward-char
|
|
[[ -n "${key[Backspace]}" ]] && bindkey "${key[Backspace]}" backward-delete-char
|
|
|
|
# Finally, make sure the terminal is in application mode, when zle is
|
|
# active. Only then are the values from $terminfo valid.
|
|
function zle-line-init () {
|
|
if [[ "${TERM}" != "linux" ]] && [[ "${TERM}" != "dumb" ]]
|
|
then
|
|
echoti smkx
|
|
fi
|
|
}
|
|
function zle-line-finish () {
|
|
if [[ "${TERM}" != "linux" ]] && [[ "${TERM}" != "dumb" ]]
|
|
then
|
|
echoti smkx
|
|
fi
|
|
}
|
|
zle -N zle-line-init
|
|
zle -N zle-line-finish
|
|
zle -N history-substring-search-up
|
|
zle -N history-substring-search-down
|
|
|
|
bindkey '^[[1;5A' history-substring-search-up
|
|
bindkey '^[[1;5B' history-substring-search-down
|
|
|
|
bindkey '^H' backward-delete-word # C-BackSpace
|
|
bindkey '^[[3;5~' delete-word # C-Del
|
|
bindkey '^[[1;5D' backward-word # C-Left
|
|
bindkey '^[[1;5C' forward-word # C-Right
|
|
|
|
|
|
if [[ "${TERM}" == rxvt* ]]; then
|
|
bindkey '^[[3^' delete-word
|
|
bindkey '^[Od' backward-word
|
|
bindkey '^[Oc' forward-word
|
|
bindkey '^[Oa' history-substring-search-up
|
|
bindkey '^[Ob' history-substring-search-down
|
|
fi
|
|
|
|
# termux claims it is xterm <https://github.com/termux/termux-app/issues/2744>
|
|
if [[ ${TERM} == xterm* && ! -v TERMUX_APP_PID ]]; then
|
|
bindkey '^H' backward-delete-char
|
|
bindkey '^?' backward-delete-word
|
|
fi
|
|
|
|
|
|
bindkey '\eu' undo # Alt+u
|
|
bindkey '\eU' redo # Alt+Shift+u
|
|
|
|
bindkey '^q' push-line-or-edit
|
|
|
|
autoload edit-command-line; zle -N edit-command-line
|
|
bindkey '^[e' edit-command-line
|
|
bindkey '^x^e' edit-command-line
|