Merge pull request #1355 from F30/key-bindings
Use terminfo key codes instead of hardcoded ones for key bindings
Diff
1diff --git a/lib/key-bindings.zsh b/lib/key-bindings.zsh
2index 49f80c8f34e22b2338ead858028a55485bb8f823..94f1842f37b5f38a5c6387ec6aae243af0820e34 100644
3--- a/lib/key-bindings.zsh
4+++ b/lib/key-bindings.zsh
5@@ -1,34 +1,43 @@
6-# TODO: Explain what some of this does..
7-
8-bindkey -e
9-bindkey '\ew' kill-region
10-bindkey -s '\el' "ls\n"
11-bindkey '^r' history-incremental-search-backward
12-bindkey "^[[5~" up-line-or-history
13-bindkey "^[[6~" down-line-or-history
14-
15-# make search up and down work, so partially type and hit up/down to find relevant stuff
16-bindkey '^[[A' up-line-or-search
17-bindkey '^[[B' down-line-or-search
18-
19-bindkey "^[[H" beginning-of-line
20-bindkey "^[[1~" beginning-of-line
21-bindkey "^[OH" beginning-of-line
22-bindkey "^[[F" end-of-line
23-bindkey "^[[4~" end-of-line
24-bindkey "^[OF" end-of-line
25-bindkey ' ' magic-space # also do history expansion on space
26-
27-bindkey "^[[1;5C" forward-word
28-bindkey "^[[1;5D" backward-word
29-
30-bindkey '^[[Z' reverse-menu-complete
31-
32-# Make the delete key (or Fn + Delete on the Mac) work instead of outputting a ~
33-bindkey '^?' backward-delete-char
34-bindkey "^[[3~" delete-char
35-bindkey "^[3;5~" delete-char
36-bindkey "\e[3~" delete-char
37+# http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html
38+# http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Zle-Builtins
39+# http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Standard-Widgets
40+
41+# Make sure that the terminal is in application mode when zle is active, since
42+# only then values from $terminfo are valid
43+if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then
44+ function zle-line-init() {
45+ echoti smkx
46+ }
47+ function zle-line-finish() {
48+ echoti rmkx
49+ }
50+ zle -N zle-line-init
51+ zle -N zle-line-finish
52+fi
53+
54+bindkey -e # Use emacs key bindings
55+
56+bindkey '\ew' kill-region # [Esc-w] - Kill from the cursor to the mark
57+bindkey -s '\el' 'ls\n' # [Esc-l] - run command: ls
58+bindkey '^r' history-incremental-search-backward # [Ctrl-r] - Search backward incrementally for a specified string. The string may begin with ^ to anchor the search to the beginning of the line.
59+bindkey "${terminfo[kpp]}" up-line-or-history # [PageUp] - Up a line of history
60+bindkey "${terminfo[knp]}" down-line-or-history # [PageDown] - Down a line of history
61+
62+bindkey "${terminfo[kcuu1]}" up-line-or-search # start typing + [Up-Arrow] - fuzzy find history forward
63+bindkey "${terminfo[kcud1]}" down-line-or-search # start typing + [Down-Arrow] - fuzzy find history backward
64+
65+bindkey "${terminfo[khome]}" beginning-of-line # [Home] - Go to beginning of line
66+bindkey "${terminfo[kend]}" end-of-line # [End] - Go to end of line
67+
68+bindkey ' ' magic-space # [Space] - do history expansion
69+
70+bindkey '^[[1;5C' forward-word # [Ctrl-RightArrow] - move forward one word
71+bindkey '^[[1;5D' backward-word # [Ctrl-LeftArrow] - move backward one word
72+
73+bindkey "${terminfo[kcbt]}" reverse-menu-complete # [Shift-Tab] - move through the completion menu backwards
74+
75+bindkey '^?' backward-delete-char # [Backspace] - delete backward
76+bindkey "${terminfo[kdch1]}" delete-char # [Delete] - delete forward
7778 # Edit the current command line in $EDITOR
79 autoload -U edit-command-line