1 # http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html
2 # http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Zle-Builtins
3 # http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Standard-Widgets
5 # Make sure that the terminal is in application mode when zle is active, since
6 # only then values from $terminfo are valid
7 if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then
8 function zle-line-init() {
11 function zle-line-finish() {
15 zle -N zle-line-finish
18 # Use emacs key bindings
21 # [PageUp] - Up a line of history
22 if [[ -n "${terminfo[kpp]}" ]]; then
23 bindkey -M emacs "${terminfo[kpp]}" up-line-or-history
24 bindkey -M viins "${terminfo[kpp]}" up-line-or-history
25 bindkey -M vicmd "${terminfo[kpp]}" up-line-or-history
27 # [PageDown] - Down a line of history
28 if [[ -n "${terminfo[knp]}" ]]; then
29 bindkey -M emacs "${terminfo[knp]}" down-line-or-history
30 bindkey -M viins "${terminfo[knp]}" down-line-or-history
31 bindkey -M vicmd "${terminfo[knp]}" down-line-or-history
34 # Start typing + [Up-Arrow] - fuzzy find history forward
35 if [[ -n "${terminfo[kcuu1]}" ]]; then
36 autoload -U up-line-or-beginning-search
37 zle -N up-line-or-beginning-search
39 bindkey -M emacs "${terminfo[kcuu1]}" up-line-or-beginning-search
40 bindkey -M viins "${terminfo[kcuu1]}" up-line-or-beginning-search
41 bindkey -M vicmd "${terminfo[kcuu1]}" up-line-or-beginning-search
43 # Start typing + [Down-Arrow] - fuzzy find history backward
44 if [[ -n "${terminfo[kcud1]}" ]]; then
45 autoload -U down-line-or-beginning-search
46 zle -N down-line-or-beginning-search
48 bindkey -M emacs "${terminfo[kcud1]}" down-line-or-beginning-search
49 bindkey -M viins "${terminfo[kcud1]}" down-line-or-beginning-search
50 bindkey -M vicmd "${terminfo[kcud1]}" down-line-or-beginning-search
53 # [Home] - Go to beginning of line
54 if [[ -n "${terminfo[khome]}" ]]; then
55 bindkey -M emacs "${terminfo[khome]}" beginning-of-line
56 bindkey -M viins "${terminfo[khome]}" beginning-of-line
57 bindkey -M vicmd "${terminfo[khome]}" beginning-of-line
59 # [End] - Go to end of line
60 if [[ -n "${terminfo[kend]}" ]]; then
61 bindkey -M emacs "${terminfo[kend]}" end-of-line
62 bindkey -M viins "${terminfo[kend]}" end-of-line
63 bindkey -M vicmd "${terminfo[kend]}" end-of-line
66 # [Shift-Tab] - move through the completion menu backwards
67 if [[ -n "${terminfo[kcbt]}" ]]; then
68 bindkey -M emacs "${terminfo[kcbt]}" reverse-menu-complete
69 bindkey -M viins "${terminfo[kcbt]}" reverse-menu-complete
70 bindkey -M vicmd "${terminfo[kcbt]}" reverse-menu-complete
73 # [Backspace] - delete backward
74 bindkey -M emacs '^?' backward-delete-char
75 bindkey -M viins '^?' backward-delete-char
76 bindkey -M vicmd '^?' backward-delete-char
77 # [Delete] - delete forward
78 if [[ -n "${terminfo[kdch1]}" ]]; then
79 bindkey -M emacs "${terminfo[kdch1]}" delete-char
80 bindkey -M viins "${terminfo[kdch1]}" delete-char
81 bindkey -M vicmd "${terminfo[kdch1]}" delete-char
83 bindkey -M emacs "^[[3~" delete-char
84 bindkey -M viins "^[[3~" delete-char
85 bindkey -M vicmd "^[[3~" delete-char
87 bindkey -M emacs "^[3;5~" delete-char
88 bindkey -M viins "^[3;5~" delete-char
89 bindkey -M vicmd "^[3;5~" delete-char
92 # [Ctrl-Delete] - delete whole forward-word
93 bindkey -M emacs '^[[3;5~' kill-word
94 bindkey -M viins '^[[3;5~' kill-word
95 bindkey -M vicmd '^[[3;5~' kill-word
97 # [Ctrl-RightArrow] - move forward one word
98 bindkey -M emacs '^[[1;5C' forward-word
99 bindkey -M viins '^[[1;5C' forward-word
100 bindkey -M vicmd '^[[1;5C' forward-word
101 # [Ctrl-LeftArrow] - move backward one word
102 bindkey -M emacs '^[[1;5D' backward-word
103 bindkey -M viins '^[[1;5D' backward-word
104 bindkey -M vicmd '^[[1;5D' backward-word
107 bindkey '\ew' kill-region # [Esc-w] - Kill from the cursor to the mark
108 bindkey -s '\el' 'ls\n' # [Esc-l] - run command: ls
109 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.
110 bindkey ' ' magic-space # [Space] - don't do history expansion
113 # Edit the current command line in $EDITOR
114 autoload -U edit-command-line
115 zle -N edit-command-line
116 bindkey '\C-x\C-e' edit-command-line
119 bindkey "^[m" copy-prev-shell-word
121 # consider emacs keybindings:
123 #bindkey -e ## emacs key bindings
125 #bindkey '^[[A' up-line-or-search
126 #bindkey '^[[B' down-line-or-search
127 #bindkey '^[^[[C' emacs-forward-word
128 #bindkey '^[^[[D' emacs-backward-word
130 #bindkey -s '^X^Z' '%-^M'
131 #bindkey '^[e' expand-cmd-path
132 #bindkey '^[^I' reverse-menu-complete
133 #bindkey '^X^N' accept-and-infer-next-history
134 #bindkey '^W' kill-region
135 #bindkey '^I' complete-word
136 ## Fix weird sequence that rxvt produces
137 #bindkey -s '^[[Z' '\t'