3 if [[ "$TERM" != emacs ]] ; then
4 [[ -z "$terminfo[kdch1]" ]] || bindkey -M emacs "$terminfo[kdch1]" delete-char
5 [[ -z "$terminfo[khome]" ]] || bindkey -M emacs "$terminfo[khome]" beginning-of-line
6 [[ -z "$terminfo[kend]" ]] || bindkey -M emacs "$terminfo[kend]" end-of-line
7 [[ -z "$terminfo[kdch1]" ]] || bindkey -M vicmd "$terminfo[kdch1]" vi-delete-char
8 [[ -z "$terminfo[khome]" ]] || bindkey -M vicmd "$terminfo[khome]" vi-beginning-of-line
9 [[ -z "$terminfo[kend]" ]] || bindkey -M vicmd "$terminfo[kend]" vi-end-of-line
10 [[ -z "$terminfo[cuu1]" ]] || bindkey -M viins "$terminfo[cuu1]" vi-up-line-or-history
11 [[ -z "$terminfo[cuf1]" ]] || bindkey -M viins "$terminfo[cuf1]" vi-forward-char
12 [[ -z "$terminfo[kcuu1]" ]] || bindkey -M viins "$terminfo[kcuu1]" vi-up-line-or-history
13 [[ -z "$terminfo[kcud1]" ]] || bindkey -M viins "$terminfo[kcud1]" vi-down-line-or-history
14 [[ -z "$terminfo[kcuf1]" ]] || bindkey -M viins "$terminfo[kcuf1]" vi-forward-char
15 [[ -z "$terminfo[kcub1]" ]] || bindkey -M viins "$terminfo[kcub1]" vi-backward-char
17 [[ "$terminfo[kcuu1]" == $'\eO'* ]] && bindkey -M viins "${terminfo[kcuu1]/O/[}" vi-up-line-or-history
18 [[ "$terminfo[kcud1]" == $'\eO'* ]] && bindkey -M viins "${terminfo[kcud1]/O/[}" vi-down-line-or-history
19 [[ "$terminfo[kcuf1]" == $'\eO'* ]] && bindkey -M viins "${terminfo[kcuf1]/O/[}" vi-forward-char
20 [[ "$terminfo[kcub1]" == $'\eO'* ]] && bindkey -M viins "${terminfo[kcub1]/O/[}" vi-backward-char
21 [[ "$terminfo[khome]" == $'\eO'* ]] && bindkey -M viins "${terminfo[khome]/O/[}" beginning-of-line
22 [[ "$terminfo[kend]" == $'\eO'* ]] && bindkey -M viins "${terminfo[kend]/O/[}" end-of-line
23 [[ "$terminfo[khome]" == $'\eO'* ]] && bindkey -M emacs "${terminfo[khome]/O/[}" beginning-of-line
24 [[ "$terminfo[kend]" == $'\eO'* ]] && bindkey -M emacs "${terminfo[kend]/O/[}" end-of-line
27 ## keybindings (run 'bindkeys' for details, more details via man zshzle)
28 # use emacs style per default:
33 #if [[ "$TERM" == screen ]] ; then
34 bindkey '\e[1~' beginning-of-line # home
35 bindkey '\e[4~' end-of-line # end
36 bindkey '\e[A' up-line-or-search # cursor up
37 bindkey '\e[B' down-line-or-search # <ESC>-
39 bindkey '^xp' history-beginning-search-backward
40 bindkey '^xP' history-beginning-search-forward
41 # bindkey -s '^L' "|less\n" # ctrl-L pipes to less
42 # bindkey -s '^B' " &\n" # ctrl-B runs it in the background
43 # if terminal type is set to 'rxvt':
44 bindkey '\e[7~' beginning-of-line # home
45 bindkey '\e[8~' end-of-line # end
48 # insert unicode character
49 # usage example: 'ctrl-x i' 00A7 'ctrl-x i' will give you an §
50 # See for example http://unicode.org/charts/ for unicode characters code
51 zrcautoload insert-unicode-char
52 zle -N insert-unicode-char
53 #k# Insert Unicode character
54 bindkey '^Xi' insert-unicode-char
56 #m# k Shift-tab Perform backwards menu completion
57 if [[ -n "$terminfo[kcbt]" ]]; then
58 bindkey "$terminfo[kcbt]" reverse-menu-complete
59 elif [[ -n "$terminfo[cbt]" ]]; then # required for GNU screen
60 bindkey "$terminfo[cbt]" reverse-menu-complete
63 ## toggle the ,. abbreviation feature on/off
64 # NOABBREVIATION: default abbreviation-state
65 # 0 - enabled (default)
67 NOABBREVIATION=${NOABBREVIATION:-0}
69 grml_toggle_abbrev() {
70 if (( ${NOABBREVIATION} > 0 )) ; then
77 zle -N grml_toggle_abbrev
78 bindkey '^xA' grml_toggle_abbrev
80 # add a command line to the shells history without executing it
85 zle -N commit-to-history
86 bindkey "^x^h" commit-to-history
88 # only slash should be considered as a word separator:
89 slash-backward-kill-word() {
90 local WORDCHARS="${WORDCHARS:s@/@}"
92 zle backward-kill-word
94 zle -N slash-backward-kill-word
96 #k# Kill everything in a word up to its last \kbd{/}
97 bindkey '\ev' slash-backward-kill-word
99 # use the new *-pattern-* widgets for incremental history search
101 bindkey '^r' history-incremental-pattern-search-backward
102 bindkey '^s' history-incremental-pattern-search-forward
105 if zrcautoload insert-files && zle -N insert-files ; then
107 bindkey "^Xf" insert-files # C-x-f
110 bindkey ' ' magic-space # also do history expansion on space
111 #k# Trigger menu-complete
112 bindkey '\ei' menu-complete # menu completion via esc-i
114 # press esc-e for editing command line in $EDITOR or $VISUAL
115 if zrcautoload edit-command-line && zle -N edit-command-line ; then
116 #k# Edit the current line in \kbd{\$EDITOR}
117 bindkey '\ee' edit-command-line
120 if [[ -n ${(k)modules[zsh/complist]} ]] ; then
121 #k# menu selection: pick item but stay in the menu
122 bindkey -M menuselect '\e^M' accept-and-menu-complete
124 # accept a completion and try to complete again by using menu
125 # completion; very useful with completing directories
126 # by using 'undo' one's got a simple file browser
127 bindkey -M menuselect '^o' accept-and-infer-next-history
130 # press "ctrl-e d" to insert the actual date in the form yyyy-mm-dd
131 _bkdate() { BUFFER="$BUFFER$(date '+%F')"; CURSOR=$#BUFFER; }
134 #k# Insert a timestamp on the command line (yyyy-mm-dd)
135 bindkey '^Ed' _bkdate
137 # press esc-m for inserting last typed word again (thanks to caphuso!)
138 insert-last-typed-word() { zle insert-last-word -- 0 -1 };
139 zle -N insert-last-typed-word;
141 #k# Insert last typed word
142 bindkey "\em" insert-last-typed-word
144 function grml-zsh-fg() {
145 if (( ${#jobstates} )); then
147 [[ -o hist_ignore_space ]] && BUFFER=' ' || BUFFER=''
151 zle -M 'No background jobs. Doing nothing.'
155 #k# A smart shortcut for \kbd{fg<enter>}
156 bindkey '^z' grml-zsh-fg
158 # run command line as user root via sudo:
159 sudo-command-line() {
160 [[ -z $BUFFER ]] && zle up-history
161 [[ $BUFFER != sudo\ * ]] && BUFFER="sudo $BUFFER"
164 zle -N sudo-command-line
166 #k# Put the current command line into a \kbd{sudo} call
167 bindkey "^Os" sudo-command-line
169 ### jump behind the first word on the cmdline.
170 ### useful to add options.
171 function jump_after_first_word() {
175 if (( ${#words} <= 1 )) ; then
178 CURSOR=${#${words[1]}}
181 zle -N jump_after_first_word
183 bindkey '^x1' jump_after_first_word