1# Stolen from ArchWiki
2
3# create a zkbd compatible hash;
4# to add other keys to this hash, see: man 5 terminfo
5typeset -A key
6
7key[Home]=${terminfo[khome]}
8
9key[End]=${terminfo[kend]}
10key[Insert]=${terminfo[kich1]}
11key[Delete]=${terminfo[kdch1]}
12key[Up]=${terminfo[kcuu1]}
13key[Down]=${terminfo[kcud1]}
14key[Left]=${terminfo[kcub1]}
15key[Right]=${terminfo[kcuf1]}
16key[PageUp]=${terminfo[kpp]}
17key[PageDown]=${terminfo[knp]}
18
19# setup key accordingly
20[[ -n "${key[Home]}" ]] && bindkey "${key[Home]}" beginning-of-line
21[[ -n "${key[End]}" ]] && bindkey "${key[End]}" end-of-line
22[[ -n "${key[Insert]}" ]] && bindkey "${key[Insert]}" overwrite-mode
23[[ -n "${key[Delete]}" ]] && bindkey "${key[Delete]}" delete-char
24[[ -n "${key[Up]}" ]] && bindkey "${key[Up]}" up-line-or-history
25[[ -n "${key[Down]}" ]] && bindkey "${key[Down]}" down-line-or-history
26[[ -n "${key[Left]}" ]] && bindkey "${key[Left]}" backward-char
27[[ -n "${key[Right]}" ]] && bindkey "${key[Right]}" forward-char
28[[ -n "${key[PageUp]}" ]] && bindkey "${key[PageUp]}" beginning-of-buffer-or-history
29[[ -n "${key[PageDown]}" ]] && bindkey "${key[PageDown]}" end-of-buffer-or-history
30
31# Finally, make sure the terminal is in application mode, when zle is
32# active. Only then are the values from $terminfo valid.
33if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then
34 function zle-line-init () {
35 printf '%s' "${terminfo[smkx]}"
36 }
37 function zle-line-finish () {
38 printf '%s' "${terminfo[rmkx]}"
39 }
40 zle -N zle-line-init
41 zle -N zle-line-finish
42fi