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