-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
359 lines (321 loc) · 12.2 KB
/
.vimrc
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
if !has('nvim')
set nocompatible
endif
let g:netrw_bufsettings='noma nomod nu rnu nobl nowrap ro'
let g:netrw_list_hide = '\(^\|\s\s\)\zs\.\S\+'
" Makes '.' command of tpope/vim-vinegar not working
" let g:netrw_liststyle=3
let g:python_host_prog='/usr/bin/python3'
let g:markdown_fenced_languages = ['sh', 'bash=sh', 'shell=sh', 'python', 'json', 'vim', 'diff', 'toml']
" Support strikethrough
let &t_Ts = "\e[9m"
let &t_Te = "\e[29m"
" Support undercurl
let &t_Cs = "\e[4:3m"
let &t_Ce = "\e[4:0m"
" set termguicolors
" set background=light
set background=dark
syntax enable
" Customizes all colorschemes
function! s:tweak_colors()
hi DiffAdd ctermfg=black ctermbg=green
hi diffAdded ctermfg=green ctermbg=black
hi DiffChange ctermfg=black ctermbg=yellow
hi DiffDelete ctermfg=black ctermbg=red
hi diffRemoved ctermfg=red ctermbg=black
hi SpellBad ctermfg=red
hi SpellCap ctermfg=blue
" Highlight the search pattern _while typing_ (e.g. `/IncSearch`).
" This is separate from the `hi Search`, which highlights the last search
" pattern (e.g. `/IncSearch<CR>`)
hi IncSearch ctermfg=red cterm=bold
endfunction
" Customizes `codedark` scheme
" TODO consider moving it to the `codedark`'s file?
" that would remove the need for this autocmd function and I could define colors
" for 256colorless terminal easily
function! s:tweak_codedark_colors()
hi SpecialKey ctermfg=240
" From 'octol/vim-cpp-enhanced-highlight'
hi cCustomClassName ctermfg=43
" Make H1 distinguishable from H2-6 to make it easier to catch if it's
" incorrectly in the middle of higher-level headings;
" also, wanted the opportunity to use the beautiful `ctermfg=43` for something
hi markdownH1 ctermfg=43 cterm=bold
" hi markdownH1 ctermfg=75 cterm=bold,reverse
" Headings and code colorization inspired by:
" https://github.com/charmbracelet/glow
hi markdownH2 ctermfg=75 cterm=bold
hi markdownH3 ctermfg=75 cterm=bold
hi markdownH4 ctermfg=75 cterm=bold
hi markdownH5 ctermfg=75 cterm=bold
hi markdownH6 ctermfg=75 cterm=bold
hi markdownHeadingDelimiter ctermfg=75 cterm=bold
hi markdownCode ctermfg=203
hi markdownCodeDelimiter ctermfg=203
" Highlight the current match for the last search pattern to distinguish it
" from other matches
hi CurSearch ctermbg=239 cterm=underline
endfunction
" To avoid losing my customization after changing colorscheme and changing it back
" Source: https://github.com/junegunn/goyo.vim/blob/7f5d35a65510083ea5c2d0941797244b9963d4a9/README.md#faq
autocmd! ColorScheme * call s:tweak_colors()
autocmd! ColorScheme codedark call s:tweak_codedark_colors()
if $TERM=~'256color'
colorscheme codedark
else
" TODO test how `codedark` would work on the terminal without 256 color support;
" that would simplify syntax highlighting configuration significantly
colorscheme default
endif
" Check if Vundle plugin manager is installed by checking if the README file
" exists because `filereadable` doesn't handle directories
if filereadable(expand('~/.vim/bundle/Vundle.vim/README.md'))
" Required by Vundle
filetype off
" Set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
Plugin 'airblade/vim-gitgutter'
if has('nvim') || v:version > 800
set signcolumn=yes
else
let g:gitgutter_sign_column_always=1
endif
if $TERM=~'xterm' || $PRESERVED_TERM=~'xterm'
let g:gitgutter_sign_added='▌'
let g:gitgutter_sign_modified='▌'
let g:gitgutter_sign_removed='▂'
let g:gitgutter_sign_removed_first_line='▔'
let g:gitgutter_sign_removed_above_and_below='▞'
let g:gitgutter_sign_modified_removed='▛'
endif
hi GitGutterAdd ctermfg=darkgreen
hi GitGutterChange ctermfg=darkblue
hi GitGutterDelete ctermfg=darkred
hi GitGutterChangeDelete ctermfg=darkmagenta
Plugin 'hdima/python-syntax'
let python_highlight_all=1
let python_highlight_file_headers_as_comments=1
Plugin 'octol/vim-cpp-enhanced-highlight'
" Works only with classes, not structures, which introduce inconsistency
let g:cpp_class_decl_highlight=0
let g:cpp_class_scope_highlight=1
let g:cpp_member_variable_highlight=1
" Choose either of the following two:
" " 1. Lag issues
" let g:cpp_experimental_simple_template_highlight=1
" " 2. Highlighting issues with std::cout << '> '
" let g:cpp_experimental_template_highlight=1
Plugin 'tpope/vim-commentary'
Plugin 'tpope/vim-repeat'
Plugin 'tpope/vim-vinegar'
" By default, the plugin overrides `-` which (in normal mode outside the
" Netrw) allows to go [count] lines upward, on the first non-blank character
" (complementary to `+`).
" As opposed to the `+`, however, the `-` does _not_ have the alternative
" keybindings, so the plugin removes possibility to use it altogether.
" Therefore, we bring back the original behavior of `-` by remapping the
" plugin's behavior to another keybinding.
noremap <leader>- <Plug>VinegarUp
Plugin 'junegunn/goyo.vim'
function! s:goyo_enter()
set scrolloff=999
endfunction
function! s:goyo_leave()
let &scrolloff=s:scrolloff
endfunction
autocmd! User GoyoEnter nested call <SID>goyo_enter()
autocmd! User GoyoLeave nested call <SID>goyo_leave()
Plugin 'tpope/vim-fugitive'
" Support for GitHub in `:GBrowse`
Plugin 'tpope/vim-rhubarb'
Plugin 'whiteinge/diffconflicts'
" For instructions how to install the latest supported version of LanguageTool
" (5.9), see:
" https://github.com/dpelle/vim-LanguageTool/issues/33#issuecomment-1873818550
" https://stackoverflow.com/a/46306176/5875021
Plugin 'dpelle/vim-LanguageTool'
let g:languagetool_cmd='languagetool'
hi link LanguageToolGrammarError SpellCap
hi link LanguageToolSpellingError SpellBad
Plugin 'godlygeek/tabular'
call vundle#end()
filetype plugin indent on
endif
if !has('nvim')
set autoindent
set autoread
set backspace=indent,eol,start
set backupdir=~/.vim/backup
set directory=~/.vim/swap//
set encoding=utf-8
set formatoptions=jcroql
set history=10000
set hlsearch
set incsearch
set langnoremap
set laststatus=2
set mouse=a
set nrformats=bin,hex
set sessionoptions=blank,buffers,curdir,folds,help,tabpages,winsize
set smarttab
set tabpagemax=50
set ttyfast
set undodir=~/.vim/undo
set viminfo=!,'100,<50,s10,h
set wildmenu
endif
set breakindent
set cinoptions=j1
set expandtab
set linebreak
set list
if $TERM=~'xterm' || $PRESERVED_TERM=~'xterm'
" `nbsp` is using a common Unicode representation
" Source: https://en.wikipedia.org/w/index.php?title=Whitespace_character&oldid=1122350113#Substitute_images
" `tab` was using it too (the '⪫' character), but while my macOS machine
" renders it correctly, my Linux machine does not
set listchars=tab:▸\ ,trail:█,extends:›,precedes:‹,nbsp:⍽
else
set listchars=tab:\|\ ,trail:#,extends:>,precedes:<,nbsp:!
endif
set number relativenumber
set previewheight=5
set ruler
let s:scrolloff=3
let &scrolloff=s:scrolloff
set shiftwidth=4
" Redirect STDERR because `uname -o` is an illegal option on macOS
let is_android=substitute(system('uname -o 2>/dev/null || uname -s'), '\n', '', '') == 'Android'
" Do not use `↪` on Android because it is ugly there (or at least on my Samsung
" Galaxy A50)
if !is_android && ($TERM=~'xterm' || $PRESERVED_TERM=~'xterm')
set showbreak=↪\ "
else
set showbreak=\\\ "
endif
set showcmd
set splitbelow
set splitright
set statusline=[%n]\ %f\ %<%y[%{&ff}]%m%r%w%=%l/%L:%c%V\ \|\ %{strftime(\"%F\ %T\",getftime(expand(\"%:p\")))}
set tabstop=4
set undofile
set nrformats=alpha,bin,hex
set updatetime=250
set ignorecase
set tagcase=followscs
set smartcase
set textwidth=80
" If `formatoptions` is updated via the plain:
" ```
" set formatoptions-=…
" ```
" it is overidden by `/usr/share/vim/…/ftplugin/*.vim` files.
" One way to address that is to use `autocmd` as below
" Source: https://vi.stackexchange.com/a/26130
augroup FormatOptions
autocmd!
autocmd FileType * setlocal formatoptions-=c
autocmd FileType * setlocal formatoptions-=t
augroup end
" 80 and 120 are the most common line lengths I've encountered in my daily work,
" while 88 is the Black's default[^1].
" This is set to +1 value (instead of 80,88,120), to show the color column right
" _after_ each length (similar to how visual guides in PyCharm are displayed).
"
" [^1]: https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#line-length
set colorcolumn=81,89,121
" `noinsert` is crucial when using `fuzzy` to allow editing the initial string
" if the list of matches is unsatisfying
set completeopt=menu,menuone,preview,noinsert,fuzzy
" Delete trailing whitespaces
nnoremap <leader>d<space> :%s/\s\+$//g<enter>
" Yank current filepath and line number to the + register
nnoremap <leader>yf :let @+ = expand("%:p") . ":" . line(".")<enter>
" Expanded version of `gf`:
" Edit existing _or new file_ whose name is under or after the cursor
nnoremap <leader>gf :e <cfile><CR>
" Enable spellchecking
nnoremap <leader>esp :setlocal spell spelllang=pl,en<CR>
" Disable spellchecking
nnoremap <leader>dsp :setlocal nospell<CR>
" Clear search highlighting
nnoremap <leader>n :noh<CR>
" Insert to do item
nnoremap <leader>iti o<C-D>- [ ]<Space>
" Insert current date
nnoremap <leader>idd "=strftime('%F')<CR>p
" Insert current datetime
nnoremap <leader>idt "=strftime('%F %R')<CR>p
" Insert current timezone-aware datetime
nnoremap <leader>idz "=strftime('%F %R %Z')<CR>p
" Insert line numbering
xnoremap <leader>iln :!nl -s'. '<CR>gv=
" Convert the current file from `dos` to `unix` fileformat
nnoremap <leader>unix :set fileformat=unix<CR>
" Use arrow keys to jump between buffers
" Source: https://github.com/jdavis/dotfiles/blob/62435dc83dd444be605e9ba204a3033e7192f3e4/.vimrc#L278..L280
map <right> :bn<CR>
map <left> :bp<CR>
" Change `'` to `"` globally in the line
nnoremap <leader>' :s/'/"/g<CR>
" Remove parentheses `()`, (square) brackets `[]`
" or braces (curly brackets) `{}` around an entity, e.g.
" `(foo bar baz)` -> `foo bar baz`
" `[foo bar baz]` -> `foo bar baz`
" `{foo bar baz}` -> `foo bar baz`
nnoremap <leader>d) di("_d%P
nnoremap <leader>d] di["_d%P
nnoremap <leader>d} di{"_d%P
" Source vimrc
nnoremap <leader>ss :source $MYVIMRC<CR>
" Search next/previous WORD, see :help WORD
nnoremap <leader>* yiW/\V<C-r>"<CR>
nnoremap <leader># yiW?\V<C-r>"<CR>
" Run inline `curl` command (HTTP request) and put the output (HTTP response)
" below the command, and reformat the output
" - Supports both single-line and multiline `curl` command
" - Assumes that the response is in JSON format
" - External dependencies: `bash` and `jq`
nnoremap <leader>! vipy}o<CR><CR><ESC>Pvip!bash<CR>]]!!jq<CR>
" Utilize abbreviations for inserting emojis
abbreviate :warn: ⚠️
" Make it easier to remember which is which, because I always confuse the two.
"
" Unfortunately, the patterns `§1st` and `§2nd` that I have configured globally
" in the macOS' settings (which does not work in the terminal) and I'm used to,
" cannot be configured in Vim because it doesn't support such pattern (`§` is
" treated as a non-keyword character; see the explanation of `full-id`, `end-id`
" and `non-id` in `:help abbreviations`)
abbreviate the1st the former
abbreviate the2nd the latter
if has("patch-8.1.0360")
set diffopt+=internal,algorithm:patience
endif
if !has('gui_running') && &term =~ '^\%(screen\|tmux\)'
" Better mouse support, see :help 'ttymouse'
set ttymouse=sgr
" Enable bracketed paste mode, see :help xterm-bracketed-paste
let &t_BE = "\<Esc>[?2004h"
let &t_BD = "\<Esc>[?2004l"
let &t_PS = "\<Esc>[200~"
let &t_PE = "\<Esc>[201~"
" Enable focus event tracking, see :help xterm-focus-event
let &t_fe = "\<Esc>[?1004h"
let &t_fd = "\<Esc>[?1004l"
execute "set <FocusGained>=\<Esc>[I"
execute "set <FocusLost>=\<Esc>[O"
" Enable modified arrow keys, see :help arrow_modifiers
execute "silent! set <xUp>=\<Esc>[@;*A"
execute "silent! set <xDown>=\<Esc>[@;*B"
execute "silent! set <xRight>=\<Esc>[@;*C"
execute "silent! set <xLeft>=\<Esc>[@;*D"
endif
" If available, use `ripgrep` as vim's external grep
if executable('rg')
set grepprg=rg\ --vimgrep
endif