1
0
Fork 0

Bind Ctrl+Left to emacs-backward-word (and Right to forward)

Binds some additional sequences to emacs-backward-word and
emacs-forward-word. The problem is that terminfo doesn't know about
Ctrl+ArrowKeys, so one has to resort to using raw sequences as used
in the wild. The sequences were copied from Debian's /etc/inputrc
(readline configuration), so they should be fairly portable.
It works in xterm and rxvt terminals and doesn't work on
TERM=linux (virtual console) as Ctrl+Arrows send the same sequence
as Arrows alone.

http://zshwiki.org/home/zle/bindkeys
http://sources.debian.net/src/readline6/6.2+dfsg-0.1/debian/inputrc?hl=44#L44
pull/563/head
kernc 11 years ago committed by Kernc
parent 7722dd4400
commit db48ad6669

@ -29,6 +29,8 @@ zmodload zsh/terminfo
typeset -gA key_info
key_info=(
'Control' '\C-'
'ControlLeft' '\e[1;5D \e[5D \e\e[D' # sequences from Debian's inputrc
'ControlRight' '\e[1;5C \e[5C \e\e[C'
'Escape' '\e'
'Meta' '\M-'
'Backspace' "^?"
@ -57,6 +59,12 @@ key_info=(
'BackTab' "$terminfo[kcbt]"
)
# additionally from Debian's inputrc
if [[ "$TERM" = *rxvt* ]]; then
key_info[ControlLeft]+=' \eOd'
key_info[ControlRight]+=' \eOc'
fi
# Set empty $key_info values to an invalid UTF-8 sequence to induce silent
# bindkey failure.
for key in "${(k)key_info[@]}"; do
@ -206,10 +214,12 @@ bindkey -d
# Emacs Key Bindings
#
for key ("$key_info[Escape]"{B,b}) bindkey -M emacs "$key" emacs-backward-word
for key ("$key_info[Escape]"{F,f}) bindkey -M emacs "$key" emacs-forward-word
bindkey -M emacs "$key_info[Escape]$key_info[Left]" emacs-backward-word
bindkey -M emacs "$key_info[Escape]$key_info[Right]" emacs-forward-word
for key ("${(s: :)key_info[ControlLeft]}" \
"$key_info[Escape]"{B,b} "$key_info[Escape]$key_info[Left]")
bindkey -M emacs "$key" emacs-backward-word
for key ("${(s: :)key_info[ControlRight]}" \
"$key_info[Escape]"{F,f} "$key_info[Escape]$key_info[Right]")
bindkey -M emacs "$key" emacs-forward-word
# Kill to the beginning of the line.
for key in "$key_info[Escape]"{K,k}

Loading…
Cancel
Save