# vim: ft=zsh # # key binding configuration # # 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]} key[CtrlLeft]=${terminfo[kLFT5]} key[CtrlRight]=${terminfo[kRIT5]} # setup keybindings! bindkey -v export KEYTIMEOUT=1 bindkey-both() { bindkey "$@" bindkey -a "$@" } [[ -n "${key[Home]}" ]] && bindkey-both "${key[Home]}" beginning-of-line [[ -n "${key[End]}" ]] && bindkey-both "${key[End]}" end-of-line [[ -n "${key[Insert]}" ]] && bindkey-both "${key[Insert]}" overwrite-mode [[ -n "${key[Delete]}" ]] && bindkey-both "${key[Delete]}" backward-delete-char [[ -n "${key[Up]}" ]] && bindkey-both "${key[Up]}" up-line-or-history [[ -n "${key[Down]}" ]] && bindkey-both "${key[Down]}" down-line-or-history [[ -n "${key[Left]}" ]] && bindkey-both "${key[Left]}" backward-char [[ -n "${key[Right]}" ]] && bindkey-both "${key[Right]}" forward-char [[ -n "${key[Backspace]}" ]] && bindkey "${key[Backspace]}" backward-delete-char [[ -n "${key[PageUp]}" ]] && bindkey-both "${key[PageUp]}" up-history [[ -n "${key[PageDown]}" ]] && bindkey-both "${key[PageDown]}" down-history [[ -n "${key[CtrlLeft]}" ]] && bindkey-both "${key[CtrlLeft]}" backward-word [[ -n "${key[CtrlRight]}" ]] && bindkey-both "${key[CtrlRight]}" forward-word bindkey-both '^P' up-history bindkey-both '^N' down-history bindkey '^h' backward-delete-char bindkey '^w' backward-kill-word bindkey-both '^r' history-incremental-search-backward bindkey -a '/' history-incremental-search-backward # https://github.com/romkatv/zsh4humans/issues/7 bindkey-both "^[[H" beginning-of-line bindkey-both "^[[F" end-of-line # Finally, make sure the terminal is in application mode, when zle is # active. Only then are the values from $terminfo valid. if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then function enter-editing-mode () { printf '%s' "${terminfo[smkx]}" } function exit-editing-mode () { printf '%s' "${terminfo[rmkx]}" } zle -N zle-line-init enter-editing-mode zle -N zle-line-finish exit-editing-mode fi