-
Notifications
You must be signed in to change notification settings - Fork 3
/
init.zsh
124 lines (106 loc) · 3.99 KB
/
init.zsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#
# Editor and input char assignment
#
[[ ${TERM} != dumb ]] && () {
# Use human-friendly identifiers.
zmodload -F zsh/terminfo +b:echoti +p:terminfo
typeset -gA key_info
key_info=(
Control '\C-'
ControlLeft '\e[1;5D \e[5D \e\e[D \eOd \eOD'
ControlRight '\e[1;5C \e[5C \e\e[C \eOc \eOC'
Escape '\e'
Meta '\M-'
Backspace '^?'
Delete '^[[3~'
BackTab "${terminfo[kcbt]}"
Left "${terminfo[kcub1]}"
Down "${terminfo[kcud1]}"
Right "${terminfo[kcuf1]}"
Up "${terminfo[kcuu1]}"
End "${terminfo[kend]}"
F1 "${terminfo[kf1]}"
F2 "${terminfo[kf2]}"
F3 "${terminfo[kf3]}"
F4 "${terminfo[kf4]}"
F5 "${terminfo[kf5]}"
F6 "${terminfo[kf6]}"
F7 "${terminfo[kf7]}"
F8 "${terminfo[kf8]}"
F9 "${terminfo[kf9]}"
F10 "${terminfo[kf10]}"
F11 "${terminfo[kf11]}"
F12 "${terminfo[kf12]}"
Home "${terminfo[khome]}"
Insert "${terminfo[kich1]}"
PageDown "${terminfo[knp]}"
PageUp "${terminfo[kpp]}"
)
# Bind the keys
local key
for key (${(s: :)key_info[ControlLeft]}) bindkey ${key} backward-word
for key (${(s: :)key_info[ControlRight]}) bindkey ${key} forward-word
bindkey ${key_info[Backspace]} backward-delete-char
bindkey ${key_info[Delete]} delete-char
if [[ -n ${key_info[Home]} ]] bindkey ${key_info[Home]} beginning-of-line
if [[ -n ${key_info[End]} ]] bindkey ${key_info[End]} end-of-line
if [[ -n ${key_info[PageUp]} ]] bindkey ${key_info[PageUp]} up-line-or-history
if [[ -n ${key_info[PageDown]} ]] bindkey ${key_info[PageDown]} down-line-or-history
if [[ -n ${key_info[Insert]} ]] bindkey ${key_info[Insert]} overwrite-mode
if [[ -n ${key_info[Left]} ]] bindkey ${key_info[Left]} backward-char
if [[ -n ${key_info[Right]} ]] bindkey ${key_info[Right]} forward-char
# Expandpace.
bindkey ' ' magic-space
# Bind insert-last-word even in viins mode
bindkey "${key_info[Escape]}." insert-last-word
bindkey "${key_info[Escape]}_" insert-last-word
# <Ctrl-x><Ctrl-e> to edit command-line in EDITOR
autoload -Uz edit-command-line && zle -N edit-command-line && \
bindkey "${key_info[Control]}x${key_info[Control]}e" edit-command-line
# Bind <Shift-Tab> to go to the previous menu item.
if [[ -n ${key_info[BackTab]} ]] bindkey ${key_info[BackTab]} reverse-menu-complete
# Use smart URL pasting and escaping.
autoload -Uz bracketed-paste-url-magic && zle -N bracketed-paste bracketed-paste-url-magic
autoload -Uz url-quote-magic && zle -N self-insert url-quote-magic
if zstyle -t ':zim:input' double-dot-expand; then
double-dot-expand() {
# Expand .. at the beginning, after space, or after any of ! " & ' / ; < > |
if [[ ${LBUFFER} == (|*[[:space:]!\"\&\'/\;\<\>|]).. ]]; then
LBUFFER+=/..
else
LBUFFER+=.
fi
}
zle -N double-dot-expand
bindkey . double-dot-expand
bindkey -M isearch . self-insert
fi
autoload -Uz is-at-least
if ! is-at-least 5.3; then
# Redisplay after completing, and avoid blank prompt after <Tab><Tab><Ctrl-C>
expand-or-complete-with-redisplay() {
print -Pn ...
zle expand-or-complete
zle redisplay
}
zle -N expand-or-complete-with-redisplay
bindkey "${key_info[Control]}I" expand-or-complete-with-redisplay
fi
if (( ${+terminfo[smkx]} && ${+terminfo[rmkx]} )); then
# Enable application mode when zle is active
start-application-mode() {
echoti smkx
}
stop-application-mode() {
echoti rmkx
}
if is-at-least 5.3; then
autoload -Uz add-zle-hook-widget && \
add-zle-hook-widget -Uz line-init start-application-mode && \
add-zle-hook-widget -Uz line-finish stop-application-mode
else
zle -N zle-line-init start-application-mode
zle -N zle-line-finish stop-application-mode
fi
fi
}