Use terminfo for keybindings

This commit is contained in:
Alexander Gehrke (crater2150) 2016-01-05 03:44:34 +01:00
parent d3fac83d7f
commit b87c12e662

View file

@ -1,43 +1,61 @@
#!/bin/zsh #!/bin/zsh
# Allow <esc>:q in vim mode to exit the shell
exit(){builtin exit;} exit(){builtin exit;}
zle -N q exit zle -N q exit
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]}
bindkey -M vicmd ! edit-command-line-tmux bindkey -M vicmd ! edit-command-line-tmux
#unicode input #unicode input
autoload -U insert-unicode-char autoload -U insert-unicode-char
bindkey $'\26u' insert-unicode-char zle -N insert-unicode-char
bindkey "^Vu" insert-unicode-char
bindkey "\e." insert-last-word bindkey "\e." insert-last-word
bindkey "^[[2~" yank # Insert [[ -n "${key[Home]}" ]] && bindkey "${key[Home]}" beginning-of-line
bindkey "^[[3~" delete-char # Del [[ -n "${key[End]}" ]] && bindkey "${key[End]}" end-of-line
bindkey "^[[5~" history-beginning-search-backward # PageUp [[ -n "${key[Insert]}" ]] && bindkey "${key[Insert]}" yank
bindkey "^[[6~" history-beginning-search-forward # PageDown [[ -n "${key[Delete]}" ]] && bindkey "${key[Delete]}" delete-char
[[ -n "${key[Up]}" ]] && bindkey "${key[Up]}" up-line-or-search
[[ -n "${key[Down]}" ]] && bindkey "${key[Down]}" down-line-or-search
[[ -n "${key[Left]}" ]] && bindkey "${key[Left]}" backward-char
[[ -n "${key[Right]}" ]] && bindkey "${key[Right]}" forward-char
[[ -n "${key[PageUp]}" ]] && bindkey "${key[PageUp]}" history-beginning-search-backward
[[ -n "${key[PageDown]}" ]] && bindkey "${key[PageDown]}" history-beginning-search-forward
bindkey "^[e" expand-cmd-path # C-e for expanding path of typed command. bindkey "^[e" expand-cmd-path # C-e for expanding path of typed command.
bindkey "^[[A" up-line-or-search # Up arrow for back-history-search.
bindkey "^[[B" down-line-or-search # Down arrow for fwd-history-search.
bindkey " " magic-space # Do history expansion on space. bindkey " " magic-space # Do history expansion on space.
bindkey $'\177' backward-delete-char #backspace bindkey $'\177' backward-delete-char #backspace
bindkey $'\10' backward-delete-word #C-backspace bindkey $'\10' backward-delete-word #C-backspace
case "$TERM" in
*xterm*|(dt|k)term)
bindkey "\e[H" beginning-of-line # Pos1
bindkey "\e[F" end-of-line # End
;;
rxvt*|Eterm)
bindkey "\e[7~" beginning-of-line # Pos1
bindkey "\e[8~" end-of-line # End
;;
linux|screen*)
bindkey "\e[1~" beginning-of-line # Pos1
bindkey "\e[4~" end-of-line # End
;;
esac
bindkey "\eOA" up-line-or-history
bindkey "\eOB" down-line-or-history
bindkey "\e[1;5D" vi-backward-blank-word bindkey "\e[1;5D" vi-backward-blank-word
bindkey "\e[1;5C" vi-forward-blank-word bindkey "\e[1;5C" vi-forward-blank-word
#bindkey . rationalise-dot #bindkey . rationalise-dot
bindkey $'\20' push-line-or-edit bindkey $'\20' push-line-or-edit
bindkey -s "^F" "fuck\n"
# 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 () {
echoti smkx
}
function zle-line-finish () {
echoti rmkx
}
zle -N zle-line-init
zle -N zle-line-finish