-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.vimrc
More file actions
412 lines (362 loc) · 14.5 KB
/
.vimrc
File metadata and controls
412 lines (362 loc) · 14.5 KB
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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
" vim: set shiftwidth=2:
set nocompatible
" Show (relative) line numbers
let g:netrw_bufsettings='noma nomod nu rnu nobl nowrap ro'
" Inspired by https://github.com/tpope/vim-vinegar:
" > All that annoying crap at the top is turned off, leaving you with nothing
" > but a list of files. This is surprisingly disorienting, but ultimately very
" > liberating. Press I to toggle until you adapt.
let g:netrw_banner=0
" Hide dotfiles by default
let g:netrw_list_hide = '\(^\|\s\s\)\zs\.\S\+'
" Display human-readable file sizes (in powers of 1024)
let g:netrw_sizestyle = 'H'
" Enable syntax highlighting for certain file types
let g:netrw_special_syntax=1
" e.g. Sat 1996-12-10 08:00:00 CEST
let g:netrw_timefmt = '%a %F %T %Z'
" Preview file in a vertically split window
let g:netrw_preview = 1
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 background=dark
syntax enable
" Customizes `torenodark` scheme
" TODO [IN PROGRESS] consider moving it to the `torenodark`'s file?
" that would remove the need for this autocmd function and I could define colors
" for 256colorless terminal easily
function! s:tweak_torenodark_colors()
" EXPERIMENT: see how I like the updated version from the latest codedark
" (applied in `torenodark` colorscheme)
" hi DiffAdd ctermfg=green ctermbg=NONE
" hi DiffChange ctermfg=green ctermbg=NONE
" hi DiffText ctermfg=black ctermbg=green
" hi DiffDelete ctermfg=black ctermbg=red
" EXPERIMENT: limit this customization to `torenodark`, not every colorscheme
" (applied in `torenodark` colorscheme)
" hi SpellBad ctermfg=red ctermbg=NONE cterm=undercurl
" hi SpellCap ctermfg=blue ctermbg=NONE cterm=undercurl
" hi SpellLocal ctermfg=green ctermbg=NONE cterm=undercurl
" hi SpellRare ctermfg=magenta ctermbg=NONE cterm=undercurl
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 torenodark call s:tweak_torenodark_colors()
" 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 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
" Required to see gitgutter sings immediately
set updatetime=250
Plugin 'hdima/python-syntax'
let python_highlight_all=1
let python_highlight_file_headers_as_comments=1
Plugin 'tpope/vim-commentary'
Plugin 'tpope/vim-repeat'
Plugin 'junegunn/goyo.vim'
function! s:goyo_enter()
set number relativenumber
endfunction
autocmd! User GoyoEnter nested call <SID>goyo_enter()
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'
Plugin 'godlygeek/tabular'
Plugin 'preservim/vim-wordy'
Plugin 'tomasiser/vim-code-dark'
call vundle#end()
filetype plugin indent on
endif
if $TERM=~'256color'
colorscheme torenodark
else
" TODO test how `torenodark` would work on the terminal without 256 color support;
" that would simplify syntax highlighting configuration significantly
colorscheme default
endif
set autoindent
set autoread
set backupdir=~/.vim/backup
set directory=~/.vim/swap//
set encoding=utf-8
set formatoptions=jcroql
set history=10000
set hlsearch
set incsearch
set laststatus=2
set mouse=a
set nrformats=bin,hex
set smarttab
set undodir=~/.vim/undo
set breakindent
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 shiftwidth=4
" Do not put any special string at the start of lines that have been wrapped.
" Instead, rely on blank space between line numbers for identifying wrapped
" lines.
set showbreak=
function! Fileformat()
if &fileformat == "unix"
return "␊"
elseif &fileformat == "dos"
return "␍␊"
elseif &fileformat == "mac"
return "␍"
endif
endfunction
set splitbelow
set splitright
" Buffer number file name (tail) truncate if too long,modified
" flag,alignment,virtual column number custom fileformat
" Example:
" 1 .vimrc + 24 ␊
set statusline=%n\ %t\ %<%M%=%v\ %{Fileformat()}
" The ruler is shown if laststatus is 0 or 1 (not 2)
set ruler
" Modified flag,alignment,virtual column number custom fileformat
" Example:
" + 24 ␊
set rulerformat=%M%=%v\ %{Fileformat()}
set undofile
" Added `blank` for better handling of ISO dates;
" without it, pressing CTRL-X on `2025-01-07` (with cursor on `7`) results in
" `2025-01-08,` while I want `2025-01-06`
" TODO research why `blank` is unavailable on Linux
set nrformats=alpha,bin,hex
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
" Display command-line completion as the popup menu instead of horizontally
set wildoptions=pum
" Complete to the longest common substring, then show wildmenu, then complete
" the next full match
set wildmode=longest:full,full
" Do _not_ insert two spaces after a dot with a join command, i.e. always insert
" only one space
set nojoinspaces
" Delete trailing whitespaces
nnoremap <leader>d<space> :s/\s\+$//g<enter>
vnoremap <leader>d<space> :s/\s\+$//g<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=en_us,pl<CR>
" Disable spellchecking
nnoremap <leader>dsp :setlocal nospell<CR>
" Clear search highlighting
nnoremap <leader>n :noh<CR>
" Put after the cursor the current date
nnoremap <leader>pdd "=strftime('%F')<CR>p
" Put before the cursor the current date
nnoremap <leader>Pdd "=strftime('%F')<CR>P
" Put after the cursor the current timezone-aware datetime
nnoremap <leader>pdt "=strftime('%F %R %Z')<CR>p
" Put before the cursor the current timezone-aware datetime
nnoremap <leader>Pdt "=strftime('%F %R %Z')<CR>P
" Insert line numbering
xnoremap <leader>iln :!nl -s'. '<CR>gv=
" Use arrow keys to jump between buffers and errors
" Source: https://github.com/jdavis/dotfiles/blob/62435dc83dd444be605e9ba204a3033e7192f3e4/.vimrc#L278..L280
noremap <right> :bn<CR>
noremap <left> :bp<CR>
noremap <up> :cp<CR>
noremap <down> :cn<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>* /\V<C-r><C-a><CR>
nnoremap <leader># ?\V<C-r><C-a><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>
" Grep all markdown headers in the current file;
" Then, use `:cl`, `:copen`, and `:cc [nr]` to navigate through the headers in a
" quicklist
nnoremap <leader>mgh :grep '^\#+ ' %<CR>
" Display total word count of the current file
nnoremap <leader>wc :echo wordcount().words<CR>
" For the current English word, show its definition in English dictionary and
" its translation to Polish, both results combined.
"
" If the result is too long, show it in a pager.
" For non-English words, the result will be nonsensical, obviously.
"
" Requires https://www.soimort.org/translate-shell
nnoremap <leader>K :!bash -c 'trans en:en <C-r><C-w> && trans en:pl <C-r><C-w>' \| less -FR<CR>
" For the current word, open a web browser and find the word's definition in the
" Cambridge dictionary
nnoremap <leader>camd :URLOpen https://duckduckgo.com/?q=!camd <C-r><C-w><CR>
" For the current word, open a web browser and find the word's definition in the
" PWN Słownik Języka Polskiego (Polish dictionary)
nnoremap <leader>sjp :URLOpen https://duckduckgo.com/?q=!sjp <C-r><C-w><CR>
" For the current word, open a web browser and find the word's definition in the
" English Wikipedia
nnoremap <leader>wen :URLOpen https://duckduckgo.com/?q=!wen <C-r><C-w><CR>
" For the current word, open a web browser and find the word's definition in the
" Polish Wikipedia
nnoremap <leader>wpl :URLOpen https://duckduckgo.com/?q=!wpl <C-r><C-w><CR>
nnoremap <leader>tag yiWo<ESC>pA<C-v><TAB><C-r>=expand("%:t")<CR><C-v><TAB>/^$<ESC>P
" Insert BCMS jira issue at the beginning
nnoremap <leader>bcms /BCMS-\d\+<CR>y3eggi[] <ESC>hP
" 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
" EXPERIMENT: Same replacements in the macOS' settings; see if it doesn't get in
" the way
abbreviate §1 the former
abbreviate §2 the latter
" According to the docs, this is set by default, but I prefer to set it
" explicitly
set diffopt+=filler,closeoff
if has("patch-8.1.0360")
set diffopt+=internal,algorithm:patience
endif
if has("patch-9.1.1243")
" Based on the screenshots from https://github.com/vim/vim/pull/16881,
" per-word diff seems more readable than per-character diff to me
set diffopt+=inline:word
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
" Below code was copy-pasted from "$VIMRUNTIME/defaults.vim"
" Only do this part when Vim was compiled with the +eval feature.
if 1
" Put these in an autocmd group, so that you can revert them with:
" ":autocmd! vimStartup"
augroup vimStartup
autocmd!
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid, when inside an event handler
" (happens when dropping a file on gvim), for a commit or rebase message
" (likely a different one than last time), and when using xxd(1) to filter
" and edit binary files (it transforms input files back and forth, causing
" them to have dual nature, so to speak) or when running the new tutor
autocmd BufReadPost *
\ let line = line("'\"")
\ | if line >= 1 && line <= line("$") && &filetype !~# 'commit'
\ && index(['xxd', 'gitrebase', 'tutor'], &filetype) == -1
\ && !&diff
\ | execute "normal! g`\""
\ | endif
augroup END
endif
" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
" Revert with: ":delcommand DiffOrig".
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
\ | wincmd p | diffthis
endif
" I like highlighting strings inside C comments.
" Revert with ":unlet c_comment_strings".
let c_comment_strings=1
" Above code was copy-pasted from "$VIMRUNTIME/defaults.vim"