104 lines
3.3 KiB
Bash
104 lines
3.3 KiB
Bash
bindkey -v
|
|
|
|
# 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
|
|
}
|
|
|
|
# Change cursor based on mode
|
|
print -n '\e[6 q'
|
|
function zle-keymap-select() {
|
|
if [[ "${TERM}" != "linux" ]] && [[ "${TERM}" != "dumb" ]]; then
|
|
if [[ "${KEYMAP}" == "viins" || "${KEYMAP}" == "main" ]]; then
|
|
print -n '\e[6 q' # beam
|
|
else
|
|
print -n '\e[2 q' # block
|
|
fi
|
|
fi
|
|
}
|
|
function _fixcursor() {
|
|
if [[ "${TERM}" != "linux" ]] && [[ "${TERM}" != "dumb" ]]; then
|
|
print -n '\e[6 q'
|
|
# print -n "\e]12;magenta\007"
|
|
fi
|
|
}
|
|
add-zsh-hook precmd _fixcursor
|
|
|
|
zle -N zle-line-init
|
|
zle -N zle-line-finish
|
|
zle -N zle-keymap-select
|
|
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 '^[^?' backward-delete-word # M-BackSpace (ESC + DEL)
|
|
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
|
|
|
|
# A lot of terminals claim they are xterm, so we check for version variable too
|
|
if [[ ${TERM} == xterm* && -v XTERM_VERSION ]]; 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
|
|
|
|
# Interactive mode in completions (filter)
|
|
bindkey -M menuselect '^xf' vi-insert
|