Mercurial > dotfiles
annotate dot_zshrc @ 537:0cc89a031281
map ctrl-u to push command to next prompt in zsh
author | Zeger Van de Vannet <zegervdv@me.com> |
---|---|
date | Thu, 27 Jan 2022 14:19:35 +0100 |
parents | 87f5a409ee83 |
children | 8e2e42add3af |
rev | line source |
---|---|
261 | 1 # vim:ft=zsh |
2 | |
262
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
3 source ~/.zsh/zsh-history-substring-search.zsh |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
4 export HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND='bg=green,fg=black' |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
5 |
531 | 6 source ~/.zsh/zsh-autosuggestions.zsh |
7 | |
536
87f5a409ee83
Add zsh syntax highlighting in shell
zegervdv <zegervdv@me.com>
parents:
535
diff
changeset
|
8 source ~/.zsh/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh |
87f5a409ee83
Add zsh syntax highlighting in shell
zegervdv <zegervdv@me.com>
parents:
535
diff
changeset
|
9 |
534
aee830df7a88
Add zsh completions for fd and rg
zegervdv <zegervdv@me.com>
parents:
533
diff
changeset
|
10 fpath=(~/.zsh/completions $fpath) |
aee830df7a88
Add zsh completions for fd and rg
zegervdv <zegervdv@me.com>
parents:
533
diff
changeset
|
11 |
293
b29fc37fe1f0
Set TERM to xterm-256color
Zeger Van de Vannet <zegervdv@me.com>
parents:
289
diff
changeset
|
12 export TERM=xterm-256color |
b29fc37fe1f0
Set TERM to xterm-256color
Zeger Van de Vannet <zegervdv@me.com>
parents:
289
diff
changeset
|
13 |
261 | 14 export LC_ALL=$LANG |
15 | |
16 PROMPT='%F{cyan}%T%f %F{red}%m%f %F{blue}%~%b%f | |
265 | 17 %j -> ' |
261 | 18 |
19 | |
265 | 20 vim_ins_mode="%F{black}%K{yellow} INS %k%f" |
266
7a275f0d38e8
Use red to indicate Normal mode in zsh prompt
zegervdv <zegervdv@me.com>
parents:
265
diff
changeset
|
21 vim_cmd_mode="%F{white}%K{red} NRM %k%f" |
261 | 22 vim_mode=$vim_ins_mode |
23 | |
262
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
24 # Cursor mapping from nyquase/vi-mode |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
25 function select_cursor() { |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
26 case $KEYMAP in |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
27 # Block cursor in normal and visual mode |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
28 vicmd) echo -ne "\e[2 q";; |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
29 # Line cursor in insert mode |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
30 main|viins) echo -ne "\e[5 q";; |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
31 # Else Block cursor |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
32 *) echo -ne "\e[2 q";; |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
33 esac |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
34 } |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
35 |
261 | 36 function zle-keymap-select { |
37 vim_mode="${${KEYMAP/vicmd/${vim_cmd_mode}}/(main|viins)/${vim_ins_mode}}" | |
38 zle reset-prompt | |
262
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
39 zle -R |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
40 select_cursor |
261 | 41 } |
42 zle -N zle-keymap-select | |
43 | |
262
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
44 function zle-line-init() { |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
45 echoti smkx |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
46 zle reset-prompt |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
47 select_cursor |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
48 } |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
49 zle -N zle-line-init |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
50 |
261 | 51 function zle-line-finish { |
52 vim_mode=$vim_ins_mode | |
262
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
53 echoti rmkx |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
54 echo -ne "\e[2 q" |
261 | 55 } |
56 zle -N zle-line-finish | |
57 | |
58 function TRAPINT() { | |
59 vim_mode=$vim_ins_mode | |
60 return $(( 128 + $1 )) | |
61 } | |
62 | |
535
f10b89e9aff3
Add git/hg info to zsh prompt
Zeger Van de Vannet <zegervdv@me.com>
parents:
534
diff
changeset
|
63 autoload -Uz vcs_info |
f10b89e9aff3
Add git/hg info to zsh prompt
Zeger Van de Vannet <zegervdv@me.com>
parents:
534
diff
changeset
|
64 zstyle ':vcs_info:*' enable git hg |
f10b89e9aff3
Add git/hg info to zsh prompt
Zeger Van de Vannet <zegervdv@me.com>
parents:
534
diff
changeset
|
65 |
f10b89e9aff3
Add git/hg info to zsh prompt
Zeger Van de Vannet <zegervdv@me.com>
parents:
534
diff
changeset
|
66 zstyle ':vcs_info:*' actionformats '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f ' |
f10b89e9aff3
Add git/hg info to zsh prompt
Zeger Van de Vannet <zegervdv@me.com>
parents:
534
diff
changeset
|
67 zstyle ':vcs_info:*' formats '%F{4}%s%F{5}%F{3} @ %F{2}%b%f' |
f10b89e9aff3
Add git/hg info to zsh prompt
Zeger Van de Vannet <zegervdv@me.com>
parents:
534
diff
changeset
|
68 zstyle ':vcs_info:hg*:*' use-simple true |
f10b89e9aff3
Add git/hg info to zsh prompt
Zeger Van de Vannet <zegervdv@me.com>
parents:
534
diff
changeset
|
69 |
f10b89e9aff3
Add git/hg info to zsh prompt
Zeger Van de Vannet <zegervdv@me.com>
parents:
534
diff
changeset
|
70 precmd () { vcs_info } |
f10b89e9aff3
Add git/hg info to zsh prompt
Zeger Van de Vannet <zegervdv@me.com>
parents:
534
diff
changeset
|
71 |
f10b89e9aff3
Add git/hg info to zsh prompt
Zeger Van de Vannet <zegervdv@me.com>
parents:
534
diff
changeset
|
72 RPROMPT='${vcs_info_msg_0_} ${vim_mode}' |
261 | 73 |
74 zmodload -i zsh/complist | |
75 | |
76 bindkey -v | |
77 | |
262
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
78 bindkey '^[[A' history-substring-search-up |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
79 bindkey '^[[B' history-substring-search-down |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
80 bindkey "$terminfo[kcuu1]" history-substring-search-up |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
81 bindkey "$terminfo[kcud1]" history-substring-search-down |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
82 bindkey '^p' history-substring-search-up |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
83 bindkey '^n' history-substring-search-down |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
84 |
533
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
85 bindkey '^f' autosuggest-accept |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
86 |
537
0cc89a031281
map ctrl-u to push command to next prompt in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
536
diff
changeset
|
87 bindkey '^u' push-line-or-edit |
0cc89a031281
map ctrl-u to push command to next prompt in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
536
diff
changeset
|
88 |
533
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
89 zmodload zsh/complist |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
90 bindkey -M menuselect 'h' vi-backward-char |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
91 bindkey -M menuselect 'k' vi-up-line-or-history |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
92 bindkey -M menuselect 'j' vi-down-line-or-history |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
93 bindkey -M menuselect 'l' vi-forward-char |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
94 |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
95 # Enter interactive search |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
96 bindkey -M menuselect '^xi' vi-insert |
531 | 97 |
263 | 98 export LESS_TERMCAP_mb=$(printf "\e[1;31m") |
99 export LESS_TERMCAP_md=$(printf "\e[1;31m") | |
100 export LESS_TERMCAP_me=$(printf "\e[0m") | |
101 export LESS_TERMCAP_se=$(printf "\e[0m") | |
102 export LESS_TERMCAP_so=$(printf "\e[1;44;33m") | |
103 export LESS_TERMCAP_ue=$(printf "\e[0m") | |
104 export LESS_TERMCAP_us=$(printf "\e[1;32m") | |
262
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
105 |
261 | 106 export CLICOLOR=1 |
107 export LS_COLORS='no=00;37:fi=00:di=00;33:ln=04;36:pi=40;33:so=01;35:bd=40;33;01:' | |
108 | |
109 # Options | |
110 setopt monitor | |
111 setopt auto_cd | |
112 setopt cdablevars | |
113 setopt pushd_ignore_dups | |
114 setopt interactive_comments | |
115 setopt append_history | |
116 setopt inc_append_history | |
117 setopt hist_ignore_dups | |
118 setopt hist_find_no_dups | |
119 setopt hist_reduce_blanks | |
120 setopt extended_history | |
121 setopt hist_expire_dups_first | |
122 setopt hist_verify | |
123 setopt share_history | |
124 setopt transient_rprompt | |
125 setopt prompt_subst | |
126 setopt multios | |
127 setopt correct_all | |
128 setopt autopushd | |
129 setopt pushdminus | |
130 setopt pushdsilent | |
131 setopt nobeep | |
132 setopt notify | |
133 REPORTTIME=5 | |
134 | |
135 HISTSIZE=3000 | |
136 SAVEHIST=3000 | |
137 HISTFILE=~/.zsh_history | |
138 | |
139 # Completion | |
140 setopt complete_in_word | |
141 setopt always_to_end | |
142 setopt auto_menu | |
533
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
143 setopt auto_param_slash |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
144 |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
145 # Enable completers |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
146 zstyle ':completion:*' completer _complete _approximate |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
147 |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
148 zstyle ':completion:*' use-cache on |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
149 zstyle ':completion:*' cache-path "$XDG_CACHE_HOME/zsh/.zcompcache" |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
150 |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
151 # file list info |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
152 zstyle ':completion:*' file-list list |
261 | 153 |
154 # activate color-completion | |
533
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
155 zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} |
261 | 156 |
157 # format on completion | |
533
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
158 zstyle ':completion:*:descriptions' format $'%{\e[0;31m%}completing %B%d%b%{\e[0m%}' |
261 | 159 |
160 # insert all expansions for expand completer | |
533
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
161 zstyle ':completion:*:expand:*' tag-order all-expansions |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
162 zstyle ':completion:*:history-words' list false |
261 | 163 |
164 # activate menu | |
533
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
165 zstyle ':completion:*:history-words' menu yes |
261 | 166 |
167 # ignore duplicate entries | |
533
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
168 zstyle ':completion:*:history-words' remove-all-dups yes |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
169 zstyle ':completion:*:history-words' stop yes |
261 | 170 |
533
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
171 zstyle ':completion:*:matches' group 'yes' |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
172 zstyle ':completion:*' group-name '' |
261 | 173 if [[ "$NOMENU" -eq 0 ]] ; then |
174 # if there are more than 5 options allow selecting from a menu | |
533
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
175 zstyle ':completion:*' menu select=5 |
261 | 176 else |
177 # don't use any menus at all | |
178 setopt no_auto_menu | |
179 fi | |
180 | |
533
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
181 zstyle ':completion:*:messages' format '%d' |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
182 zstyle ':completion:*:options' auto-description '%d' |
261 | 183 |
184 # describe options in full | |
533
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
185 zstyle ':completion:*:options' description 'yes' |
261 | 186 |
187 # complete manual by their section | |
533
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
188 zstyle ':completion:*:manuals' separate-sections true |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
189 zstyle ':completion:*:manuals.*' insert-sections true |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
190 zstyle ':completion:*:man:*' menu yes select |
261 | 191 |
192 # Search path for sudo completion | |
193 zstyle ':completion:*:sudo:*' command-path /usr/local/sbin \ | |
194 /usr/local/bin \ | |
195 /usr/sbin \ | |
196 /usr/bin \ | |
197 /sbin \ | |
198 /bin \ | |
199 /usr/X11R6/bin | |
200 | |
201 # provide .. as a completion | |
202 zstyle ':completion:*' specal-dirs .. | |
203 | |
204 # case insensitive path-completion | |
205 zstyle ':completion:*' matcher-list 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*' | |
206 | |
207 # nvim completion | |
533
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
208 zstyle ':completion:*:*:nvim:*' ignored-patterns '*.(o|hex|elf|pyc|pdf|dup)' |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
209 zstyle ':completion:*:*:nvim:*' file-sort modification |
261 | 210 |
211 autoload -U compinit && compinit | |
212 | |
213 # fg when pressing Ctrl+Z | |
214 function fancy-ctrl-z () { | |
215 if [[ $#BUFFER -eq 0 ]]; then | |
216 if [[ $(jobs | wc -l) -gt 0 ]]; then | |
217 BUFFER='fg' | |
218 zle accept-line | |
219 fi | |
220 else | |
221 zle push-input | |
222 zle clear-screen | |
223 fi | |
224 } | |
225 zle -N fancy-ctrl-z | |
226 bindkey '^Z' fancy-ctrl-z | |
227 | |
228 # Aliases | |
479 | 229 alias l="ls -haltr" |
230 alias ll="ls -haltr" | |
261 | 231 alias xclip='xclip -selection clipboard' |
269 | 232 alias view='nvim -R' |
261 | 233 |
234 # Exports | |
235 export XDG_CONFIG_HOME=$HOME/.config | |
236 export PATH=$HOME/bin:$PATH | |
237 | |
238 export EDITOR=nvim | |
239 export HGEDITOR=nvim | |
240 | |
504 | 241 export RIPGREP_CONFIG_PATH=$HOME/.config/ripgrep/ripgreprc |
506 | 242 export BAT_CONFIG_PATH=$HOME/.config/bat/config |
504 | 243 |
267 | 244 [ -f ~/.fzf.zsh ] && source ~/.fzf.zsh |
261 | 245 export FZF_DEFAULT_COMMAND='ag -g ""' |
267 | 246 [ -f ~/.zshrc.local ] && source ~/.zshrc.local |
491
f1d1eab204aa
Fix paths to nvim for SUDO_EDITOR
zegervdv <zegervdv@me.com>
parents:
490
diff
changeset
|
247 |
f1d1eab204aa
Fix paths to nvim for SUDO_EDITOR
zegervdv <zegervdv@me.com>
parents:
490
diff
changeset
|
248 # Must run after brew is loaded |
f1d1eab204aa
Fix paths to nvim for SUDO_EDITOR
zegervdv <zegervdv@me.com>
parents:
490
diff
changeset
|
249 export SUDO_EDITOR=$(which nvim) |
508 | 250 eval "$(direnv hook zsh)" |