diff --git a/lib/key-bindings.zsh b/lib/key-bindings.zsh index 5f499f3e8..0c5081abf 100644 --- a/lib/key-bindings.zsh +++ b/lib/key-bindings.zsh @@ -4,47 +4,10 @@ bindkey -e bindkey '\ew' kill-region bindkey -s '\el' "ls\n" bindkey '^r' history-incremental-search-backward -bindkey "^[[5~" up-line-or-history -bindkey "^[[6~" down-line-or-history -# make search up and down work, so partially type and hit up/down to find relevant stuff -bindkey '^[[A' up-line-or-search -bindkey '^[[B' down-line-or-search - -bindkey "^[[H" beginning-of-line -bindkey "^[[1~" beginning-of-line -bindkey "^[OH" beginning-of-line -bindkey "^[[F" end-of-line -bindkey "^[[4~" end-of-line -bindkey "^[OF" end-of-line bindkey ' ' magic-space # also do history expansion on space bindkey "^[[1;5C" forward-word bindkey "^[[1;5D" backward-word bindkey '^[[Z' reverse-menu-complete - -# Make the delete key (or Fn + Delete on the Mac) work instead of outputting a ~ -bindkey '^?' backward-delete-char -bindkey "^[[3~" delete-char -bindkey "^[3;5~" delete-char -bindkey "\e[3~" delete-char - -# consider emacs keybindings: - -#bindkey -e ## emacs key bindings -# -#bindkey '^[[A' up-line-or-search -#bindkey '^[[B' down-line-or-search -#bindkey '^[^[[C' emacs-forward-word -#bindkey '^[^[[D' emacs-backward-word -# -#bindkey -s '^X^Z' '%-^M' -#bindkey '^[e' expand-cmd-path -#bindkey '^[^I' reverse-menu-complete -#bindkey '^X^N' accept-and-infer-next-history -#bindkey '^W' kill-region -#bindkey '^I' complete-word -## Fix weird sequence that rxvt produces -#bindkey -s '^[[Z' '\t' -# diff --git a/lib/special-keys.zsh b/lib/special-keys.zsh new file mode 100644 index 000000000..ac3c41ebe --- /dev/null +++ b/lib/special-keys.zsh @@ -0,0 +1,38 @@ +#create special key keybindings (home, end, insert delete arrow keys) +#see http://zshwiki.org/home/zle/bindkeys + +# 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]} + +# 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 + +# 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 diff --git a/plugins/vi-mode/vi-mode.plugin.zsh b/plugins/vi-mode/vi-mode.plugin.zsh index a06100472..ab98ff517 100644 --- a/plugins/vi-mode/vi-mode.plugin.zsh +++ b/plugins/vi-mode/vi-mode.plugin.zsh @@ -20,6 +20,9 @@ zle -N zle-keymap-select bindkey -v +#rebind special key keybinds +source $ZSH/lib/special-keys.zsh + # if mode indicator wasn't setup by theme, define default if [[ "$MODE_INDICATOR" == "" ]]; then MODE_INDICATOR="%{$fg_bold[red]%}<%{$fg[red]%}<<%{$reset_color%}"