]>
git.r.bdr.sh - rbdr/dotfiles/blob - zsh/modules/editor.zsh
5 # Sorin Ionescu <sorin.ionescu@gmail.com>
8 # Return if requirements are not found.
9 if [[ "$TERM" == 'dumb' ]]; then
17 # Beep on error in line editor.
24 # Treat these characters as part of a word.
25 WORDCHARS
='*?_-.[]~&;!#$%^(){}<>'
27 # Use human-friendly identifiers.
32 'ControlLeft' '\e[1;5D \e[5D \e\e[D \eOd'
33 'ControlRight' '\e[1;5C \e[5C \e\e[C \eOc'
47 'F10' "$terminfo[kf10]"
48 'F11' "$terminfo[kf11]"
49 'F12' "$terminfo[kf12]"
50 'Insert' "$terminfo[kich1]"
51 'Home' "$terminfo[khome]"
52 'PageUp' "$terminfo[kpp]"
53 'End' "$terminfo[kend]"
54 'PageDown' "$terminfo[knp]"
55 'Up' "$terminfo[kcuu1]"
56 'Left' "$terminfo[kcub1]"
57 'Down' "$terminfo[kcud1]"
58 'Right' "$terminfo[kcuf1]"
59 'BackTab' "$terminfo[kcbt]"
62 # Set empty $key_info values to an invalid UTF-8 sequence to induce silent
64 for key
in "${(k)key_info[@]}"; do
65 if [[ -z "$key_info[$key]" ]]; then
74 # Allow command line editing in an external editor.
75 autoload
-Uz edit
-command-line
76 zle
-N edit
-command-line
78 # Enables terminal application mode and updates editor information.
79 function zle
-line-init {
80 # The terminal must be in application mode when ZLE is active for $terminfo
82 if (( $
+terminfo
[smkx
] )); then
83 # Enable terminal application mode.
89 # Disables terminal application mode and updates editor information.
90 function zle
-line-finish {
91 # The terminal must be in application mode when ZLE is active for $terminfo
93 if (( $
+terminfo
[rmkx
] )); then
94 # Disable terminal application mode.
98 zle
-N zle
-line-finish
100 # Displays an indicator when completing.
101 function expand-or-complete-with-indicator {
103 zstyle
-s ':prezto:module:editor:info:completing' format
'indicator'
104 print
-Pn "$indicator"
105 zle
expand-or-complete
108 zle
-N expand-or-complete-with-indicator
110 # Inserts 'sudo ' at the beginning of the line.
111 function prepend
-sudo {
112 if [[ "$BUFFER" != su
(do|)\
* ]]; then
113 BUFFER
="sudo $BUFFER"
119 # Reset to default key bindings.
126 # Edit command in an external editor.
127 bindkey
-M vicmd
"v" edit
-command-line
130 bindkey
-M vicmd
"u" undo
131 bindkey
-M vicmd
"$key_info[Control]R" redo
133 if (( $
+widgets
[history-incremental-pattern-search-backward] )); then
134 bindkey
'^R' history-incremental-pattern-search-backward
135 bindkey
-M vicmd
"?" history-incremental-pattern-search-backward
136 bindkey
-M vicmd
"/" history-incremental-pattern-search-forward
138 bindkey
'^R' history-incremental-search-backward
139 bindkey
-M vicmd
"?" history-incremental-search-backward
140 bindkey
-M vicmd
"/" history-incremental-search-forward
144 # Emacs and Vi Key Bindings
147 for keymap
in 'emacs' 'viins'; do
148 bindkey
-M "$keymap" "$key_info[Home]" beginning
-of-line
149 bindkey
-M "$keymap" "$key_info[End]" end
-of-line
151 bindkey
-M "$keymap" "$key_info[Insert]" overwrite
-mode
152 bindkey
-M "$keymap" "$key_info[Delete]" delete
-char
153 bindkey
-M "$keymap" "$key_info[Backspace]" backward
-delete-char
155 bindkey
-M "$keymap" "$key_info[Left]" backward
-char
156 bindkey
-M "$keymap" "$key_info[Right]" forward
-char
158 # Expand history on space.
159 bindkey
-M "$keymap" ' ' magic
-space
162 bindkey
-M "$keymap" "$key_info[Control]L" clear-screen
164 # Expand command name to full path.
165 for key
in "$key_info[Escape]"{E
,e
}
166 bindkey
-M "$keymap" "$key" expand-cmd-path
168 # Duplicate the previous word.
169 for key
in "$key_info[Escape]"{M
,m
}
170 bindkey
-M "$keymap" "$key" copy
-prev-shell-word
172 # Use a more flexible push-line.
173 for key
in "$key_info[Control]Q" "$key_info[Escape]"{q
,Q
}
174 bindkey
-M "$keymap" "$key" push
-line-or-edit
176 # Bind Shift + Tab to go to the previous menu item.
177 bindkey
-M "$keymap" "$key_info[BackTab]" reverse
-menu-complete
179 # Complete in the middle of word.
180 bindkey
-M "$keymap" "$key_info[Control]I" expand-or-complete
182 # Display an indicator when completing.
183 bindkey
-M "$keymap" "$key_info[Control]I" \
184 expand-or-complete-with-indicator
186 # Insert 'sudo ' at the beginning of the line.
187 bindkey
-M "$keymap" "$key_info[Control]X$key_info[Control]S" prepend
-sudo
194 # Set the key layout.
197 unset key
{,map
,bindings
}