bindkey -e

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]}

# jump from word-boundary to word-boundary by ctrl-left, ctrl-right
bindkey "" emacs-backward-word
bindkey "" emacs-forward-word
# Make word-boundaries every non-word character
export WORDCHARS=''

# Make End, Home work
bindkey "$key[Home]" beginning-of-line
bindkey "$key[End]" end-of-line

# fucking xterm destroyed them again
bindkey "[1~" beginning-of-line
bindkey "[4~" end-of-line

# this is ctrl+end, ctrl+home in xterm
bindkey "" beginning-of-line
bindkey "" end-of-line

# ctrl+arrows
bindkey "^[[1;5C" forward-word
bindkey "^[[1;5D" backward-word

# delete key
bindkey "^[[3~" delete-char

# ctrl+arrows
bindkey "^[[1;5C" forward-word
bindkey "^[[1;5D" backward-word

# delete key
bindkey "^[[3~" delete-char

bindkey "$key[PageUp]" history-beginning-search-backward
bindkey "$key[PageDown]" history-beginning-search-forward

bindkey "^i" expand-or-complete-prefix

# 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 zle-line-init () {
        printf '%s' "${terminfo[smkx]}"
    }
    function zle-line-finish () {
        printf '%s' "${terminfo[rmkx]}"
    }
    zle -N zle-line-init
    zle -N zle-line-finish
fi

autoload -U select-word-style
select-word-style bash
export WORDCHARS=''