]> gitweb.pimeys.fr Git - config-20-100.git/blob - .zsh/rc/local/25_bindkey
Ajout du zshrc, même s'il manque encore de commentaires etc.
[config-20-100.git] / .zsh / rc / local / 25_bindkey
1
2 # {{{ keybindings
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
16 # ncurses stuff:
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
25 fi
26
27 ## keybindings (run 'bindkeys' for details, more details via man zshzle)
28 # use emacs style per default:
29 bindkey -e
30 # use vi style:
31 # bindkey -v
32
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>-
38
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
46 #fi
47
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
55
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
61 fi
62
63 ## toggle the ,. abbreviation feature on/off
64 # NOABBREVIATION: default abbreviation-state
65 # 0 - enabled (default)
66 # 1 - disabled
67 NOABBREVIATION=${NOABBREVIATION:-0}
68
69 grml_toggle_abbrev() {
70 if (( ${NOABBREVIATION} > 0 )) ; then
71 NOABBREVIATION=0
72 else
73 NOABBREVIATION=1
74 fi
75 }
76
77 zle -N grml_toggle_abbrev
78 bindkey '^xA' grml_toggle_abbrev
79
80 # add a command line to the shells history without executing it
81 commit-to-history() {
82 print -s ${(z)BUFFER}
83 zle send-break
84 }
85 zle -N commit-to-history
86 bindkey "^x^h" commit-to-history
87
88 # only slash should be considered as a word separator:
89 slash-backward-kill-word() {
90 local WORDCHARS="${WORDCHARS:s@/@}"
91 # zle backward-word
92 zle backward-kill-word
93 }
94 zle -N slash-backward-kill-word
95
96 #k# Kill everything in a word up to its last \kbd{/}
97 bindkey '\ev' slash-backward-kill-word
98
99 # use the new *-pattern-* widgets for incremental history search
100 if is439 ; then
101 bindkey '^r' history-incremental-pattern-search-backward
102 bindkey '^s' history-incremental-pattern-search-forward
103 fi
104
105 if zrcautoload insert-files && zle -N insert-files ; then
106 #k# Insert files
107 bindkey "^Xf" insert-files # C-x-f
108 fi
109
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
113
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
118 fi
119
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
123
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
128 fi
129
130 # press "ctrl-e d" to insert the actual date in the form yyyy-mm-dd
131 _bkdate() { BUFFER="$BUFFER$(date '+%F')"; CURSOR=$#BUFFER; }
132 zle -N _bkdate
133
134 #k# Insert a timestamp on the command line (yyyy-mm-dd)
135 bindkey '^Ed' _bkdate
136
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;
140
141 #k# Insert last typed word
142 bindkey "\em" insert-last-typed-word
143
144 function grml-zsh-fg() {
145 if (( ${#jobstates} )); then
146 zle .push-input
147 [[ -o hist_ignore_space ]] && BUFFER=' ' || BUFFER=''
148 BUFFER="${BUFFER}fg"
149 zle .accept-line
150 else
151 zle -M 'No background jobs. Doing nothing.'
152 fi
153 }
154 zle -N grml-zsh-fg
155 #k# A smart shortcut for \kbd{fg<enter>}
156 bindkey '^z' grml-zsh-fg
157
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"
162 CURSOR=$#BUFFER
163 }
164 zle -N sudo-command-line
165
166 #k# Put the current command line into a \kbd{sudo} call
167 bindkey "^Os" sudo-command-line
168
169 ### jump behind the first word on the cmdline.
170 ### useful to add options.
171 function jump_after_first_word() {
172 local words
173 words=(${(z)BUFFER})
174
175 if (( ${#words} <= 1 )) ; then
176 CURSOR=${#BUFFER}
177 else
178 CURSOR=${#${words[1]}}
179 fi
180 }
181 zle -N jump_after_first_word
182
183 bindkey '^x1' jump_after_first_word
184 # }}}