-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
470 lines (403 loc) · 11.1 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
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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
" General {{{
set autoread
set backspace=start,indent,eol
set browsedir=buffer
if !has('nvim')
set cryptmethod=blowfish2
endif
set encoding=utf-8
set fillchars=
set formatoptions=tcroqnlj
set hidden
set list
set listchars=tab:\│\ ,space:·,multispace:·,lead:·,trail:·,extends:▸,precedes:◂
set makeprg=make
set noswapfile
set nowrap
set scrolloff=5
set showmatch
set switchbuf=usetab
set updatetime=500
set virtualedit=block
" }}}
" Paths {{{
set exrc
set path+=include
set tags=./tags;
" }}}
" Grep {{{
if has('unix')
if executable('ag')
set grepprg=ag\ --nogroup\ --nocolor\ --column\ --vimgrep
elseif executable('ack')
set grepprg=ack\ -s\ --with-filename\ --nocolor\ --nogroup\ --column
elseif executable('rg')
set grepprg=rg\ --vimgrep
endif
set grepformat=%f:%l:%c:%m,%f:%l:%m
endif
" }}}
" {{{ Quickfix
set errorformat^=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
" }}}
" {{{ Diff
set diffopt-=internal
" }}}
" Search {{{
set ignorecase
set smartcase
set infercase
set hlsearch
set incsearch
set nowrapscan
" }}}
" Completion {{{
set wildignorecase
set wildmenu
set wildmode=longest:full,full
set wildoptions=tagfile
if has('nvim')
set wildoptions+=pum
endif
set complete=.,w,b
set completeopt=menu
set pumheight=15
set omnifunc=ale#completion#OmniFunc
" }}}
" Wild Ignore {{{
set wildignore+=*/.git/*,*/.hg/*,*/.svn/*
set wildignore+=*/tmp/*,*/research-data/*,*/test-data/*
set wildignore+=*.pyc,*.pyo,*.pyd,*/__pycache__/*
set wildignore+=*.so,*.o,*.dll,*.lib,*.obj,*.exe
set wildignore+=*.ttf,*.pdf,*.xls,*.xlsx,*.doc,*.docx
set wildignore+=*.h5,*.pcl,*.dat
set wildignore+=*.tar,*.gz,*.bz2
set wildignore+=*.png,*.gif,*.jpg,*.bmp,*.ico
set wildignore+=cscope.out,tags
" }}}
" Clipboard {{{
if has('clipboard')
if has('unnamedplus')
set clipboard=unnamedplus
else
set clipboard=unnamed
endif
endif
" }}}
" Win32/64 {{{
if has('win32') || has('win64')
set fileformats=unix,dos
set shellslash
endif
" }}}
" UI {{{
set breakindent
set colorcolumn=+1
set cursorline
set display=lastline
set laststatus=2
set linebreak
set ruler
set mouse=n
set mousehide
set showbreak=\ \ >\
set splitbelow
set splitright
set winminheight=0
set winminwidth=0
if has('gui') && has('gui_running')
set guioptions=aci
if has('gui_macvim')
set antialias
set guifont=SauceCodeProNerdFontCompleteM-Regular:h14
set transparency=10
endif
else
set lazyredraw
set termguicolors
if !has('nvim')
set ttyfast
endif
set t_ut=
endif
" }}}
" Auto Commands {{{
augroup ALE
autocmd!
autocmd CursorHold * ALEHover
augroup end
augroup CursorLine
autocmd!
autocmd WinEnter * set cursorline colorcolumn=+1
autocmd WinLeave * set nocursorline colorcolumn=
autocmd InsertEnter * set nocursorline
autocmd InsertLeave * set cursorline
augroup end
augroup QuickFix
autocmd!
autocmd QuickFixCmdPost [^l]* nested cwindow
autocmd QuickFixCmdPost l* nested lwindow
augroup end
augroup ElixirLangs
au BufRead,BufNewFile *.ex,*.exs set filetype=elixir
au BufRead,BufNewFile *.eex set filetype=eelixir
augroup end
" }}}
" Syntax, Filetype {{{
syntax on
filetype on
filetype indent on
filetype plugin on
syntax sync fromstart
" }}}
" Plug-ins {{{
let g:loaded_netrw=1
let g:loaded_netrwPlugin=1
packadd! badwolf
packadd! gruvbox
packadd! papercolor-theme
packadd! tender.vim
packadd! vim-airline
packadd! vim-airline-themes
if has("nvim")
packadd! nvim-treesitter
endif
packadd! ale
packadd! quick-scope
packadd! fzf.vim
packadd! targets.vim
packadd! vim-abolish
packadd! vim-commentary
packadd! vim-dadbod
packadd! vim-gitgutter
packadd! vim-grepper
packadd! vim-repeat
packadd! vim-surround
packadd! vim-wordmotion
packadd! vim-cpp-modern
packadd! vim-cmake-syntax
packadd! vim-elixir
packadd! vim-go-syntax.git
packadd! python-syntax
packadd! vim-python-pep8-indent
" }}}
" PaperColor {{{
let g:PaperColor_Theme_Options={
\ 'language': {
\ 'python': {
\ 'highlight_builtins': 1
\ }
\ }
\ }
" }}}
" Badwolf {{{
let g:badwolf_darkgutter=1
let g:badwolf_tabline=2
" }}}
" Gruvbox {{{
let g:gruvbox_italics=1
let g:gruvbox_italicize_strings=1
let g:gruvbox_number_column='bg1'
" }}}
" Colors {{{
if has('gui_running')
set background=dark
colorscheme badwolf
else
set background=dark
colorscheme gruvbox
endif
" }}}
" Airline {{{
let g:airline_theme=has('gui_running') ? 'badwolf' : 'gruvbox'
let g:airline#extensions#wordcount#enabled=0
let g:airline#extensions#whitespace#enabled=0
let g:airline#extensions#tabline#enabled=1
let g:airline_powerline_fonts=1
" }}}
" Word Motion {{{
let g:wordmotion_prefix='<leader>'
" }}}
" ALE {{{
let g:ale_lint_on_text_changed='never'
let g:ale_lint_on_insert_leave=1
let g:ale_set_highlights=0
let g:ale_set_signs=0
let g:ale_set_balloons=0
let g:ale_hover_to_floating_preview=1
let g:ale_floating_window_border=['│', '─', '╭', '╮', '╯', '╰', '│', '─']
let g:ale_floating_preview_popup_opts={'close': 'click'}
let g:ale_fixers={
\ 'go': ['goimports', 'gopls'],
\ 'python': ['black', 'ruff']
\ }
let g:ale_linters={
\ 'cpp': ['gcc'],
\ 'go': ['golangci-lint', 'gopls'],
\ 'python': ['pyright', 'ruff']
\ }
let g:ale_go_golangci_lint_executable='~/go/bin/golangci-lint'
let g:ale_go_golangci_lint_package=1
let g:ale_go_goimports_executable='~/go/bin/goimports'
let g:ale_go_gopls_executable='~/go/bin/gopls'
let g:ale_cpp_gcc_options='-std=c++14 -Wall -Wextra -Wpedantic -Wconversion'
let g:ale_python_pyright_config={
\ 'pyright': { 'disableLanguageServices': v:true }
\ }
let g:ale_python_ruff_options='--ignore=E501,W291,E722' " line too long, trailing whitespace, bare except
" }}}
" Grepper {{{
let g:grepper = {}
let g:grepper.tools=['git', 'rg']
let g:grepper.prompt=0
" }}}
" Git Gutter {{{
let g:gitgutter_terminal_reports_focus=0
let g:gitgutter_preview_win_floating=1
" }}}
" FZF {{{
let $FZF_DEFAULT_OPTS='--layout=reverse'
let g:fzf_buffers_jump=1
let g:fzf_tags_command='ctags -R --exclude=*/__pycache__/* --python-kinds=-i --sorted=yes'
let g:fzf_layout={'window': {'height': 0.5, 'width': 0.5}}
" }}}
" Quick Scope {{{
let g:qs_highlight_on_keys=['f', 'F', 't', 'T']
" }}}
" Commands {{{
" Jump to the next diff and obtain it (repeat with @@, followed by @:)
command! -nargs=0 Fix :normal! ]cdo<CR>
" Find TODO, XXX, etc.
command! -nargs=0 Todo :lvimgrep /\#\s*\(XXX\|TODO\|NOTE\)/ %<CR>
" Find conflict markers
command! -nargs=0 Conflicts :lvimgrep />>>>>>>\|=======\|<<<<<<</ %<CR>
" Avoid the 'Hit ENTER to continue' prompts
command! -nargs=* -complete=file_in_path Grep silent! grep! <args> | redraw!
command! -nargs=* -complete=file_in_path LGrep silent! lgrep! <args> | redraw!
command! -nargs=0 Make silent! make! | redraw!
command! -nargs=0 LMake silent! lmake! | redraw!
" }}}
" Mappings {{{
" Popup navigation
inoremap <silent> <C-K> <C-R>=pumvisible() ? "\<lt>C-P>" : "\<lt>C-K>"<CR>
inoremap <silent> <C-J> <C-R>=pumvisible() ? "\<lt>C-N>" : "\<lt>C-J>"<CR>
" Alias space to leader
map <Space> <leader>
" Highlight word under cursor without jumping
nnoremap <silent> <leader>* :let @/='\<<C-R>=expand("<cword>")<CR>\>'<CR>:set hlsearch<CR>
" Change next/previous occurrence
nnoremap <silent> c; *``cgn
nnoremap <silent> c, #``cgn
" Reset search pattern
nnoremap <silent> <C-L> <C-L>:let @/="" <bar> :ALELint<CR>
" ALE shortcuts
nmap <silent> ]l <Plug>(ale_next)
nmap <silent> [l <Plug>(ale_previous)
nmap <silent> <leader>l <Plug>(ale_lint)
nmap <silent> g] <Plug>(ale_go_to_definition)
nmap <silent> g^ <Plug>(ale_find_references)
" Grepper shortcuts
nmap <silent> gs <Plug>(GrepperOperator)
vmap <silent> gs <Plug>(GrepperOperator)
" FZF shortcuts
nmap <silent> <leader>fe :Files<CR>
nmap <silent> <leader>fg :GFiles<CR>
nmap <silent> <leader>fb :Buffers<CR>
nmap <silent> <leader>ft :Tags<CR>
" Wrap a word in quotes
nnoremap <silent> <leader>q' ciw'<C-R><C-O>"'<Esc>
nnoremap <silent> <leader>q" ciw"<C-R><C-O>""<Esc>
nnoremap <silent> <leader>q" ciw"<C-R><C-O>""<Esc>
nnoremap <silent> <leader>q( ciw(<C-R><C-O>")<Esc>
nnoremap <silent> <leader>q[ ciw[<C-R><C-O>"]<Esc>
nnoremap <silent> <leader>q{ ciw{<C-R><C-O>"}<Esc>
nnoremap <silent> <leader>q< ciw<<C-R><C-O>"><Esc>
" Inverse of g]
nnoremap <silent> g[ :pop<CR>
" Preview tag
nnoremap <silent> g\ :ptjump <C-R>=expand("<cword>")<CR><CR>
" Indent and return to Visual mode
vnoremap <silent> < <gv
vnoremap <silent> > >gv
" Repeat over lines in Visual mode
vnoremap <silent> . :normal .<CR>
" Highlight text from last Insert mode
nnoremap <silent> gV `[v`]
" Add relative line motions to jump list
nnoremap <silent> <expr> k (v:count > 1 ? "m'" . v:count : '') . 'k'
nnoremap <silent> <expr> j (v:count > 1 ? "m'" . v:count : '') . 'j'
" }}}
" get_visual_selection() {{{
function! s:get_visual_selection()
let [begln, begcol] = getpos("'<")[1:2]
let [endln, endcol] = getpos("'>")[1:2]
let lines = getline(begln, endln)
let lines[-1] = lines[-1][:endcol - (&selection == 'inclusive' ? 1 : 2)]
let lines[0] = lines[0][begcol - 1:]
return join(lines, "\n")
endfunction
" }}}
" tab_complete() {{{
function! s:tab_complete(mode)
let cmd=(a:mode == "P" ? "\<C-P>" : "\<C-N>")
let bol=(strpart(getline('.'), 0, col('.')-1) =~ '^\s*$' ? 1 : 0)
if bol == 0 || pumvisible()
return cmd
else
return "\<Tab>"
endif
endfunction
inoremap <silent> <Tab> <C-R>=<SID>tab_complete("P")<CR>
inoremap <silent> <S-Tab> <C-R>=<SID>tab_complete("N")<CR>
" }}}
" google_it() {{{
let s:open_cmd=executable('xdg-open') ? 'xdg-open ' : 'open '
function! s:google_it(phrase)
let url='https://www.google.com/search?q='
let q=substitute('"'.a:phrase.'"',
\ '[^A-Za-z0-9_.~-]',
\ '\="%".printf("%02X", char2nr(submatch(0)))',
\ 'g')
call system(s:open_cmd . url . q)
endfunction
vnoremap <silent> <leader>k :call <SID>google_it(<SID>get_visual_selection())<CR>
nnoremap <silent> <leader>k :call <SID>google_it(expand("<cWORD>"))<CR>
function! s:go_to_httpstatuses(code)
let url='https://httpstatuses.com/'
let code = str2nr(a:code)
call system(s:open_cmd . url . code)
endfunction
command! -nargs=1 HttpStatus :call <SID>go_to_httpstatuses(<q-args>)
" }}}
" FZF {{{
if has('nvim')
let g:fzf_layout={'window': 'call FloatingFZF()'}
function! FloatingFZF()
" scratch, unlisted, new, empty, unnamed buffer
let buf=nvim_create_buf(v:false, v:true)
" % of the height
let height=float2nr(&lines * 0.5)
" % of the width
let width=float2nr(&columns * 0.5)
" horizontal position (centered)
let xpos=float2nr((&columns - width) / 2)
" vertical position (centered)
let ypos=float2nr((&lines - height) / 2)
let opts={
\ 'relative': 'editor',
\ 'row': ypos,
\ 'col': xpos,
\ 'width': width,
\ 'height': height
\ }
call nvim_open_win(buf, v:true, opts)
endfunction
endif
" }}}
" Local {{{
let localrc=glob('~/.vimrc.local')
if filereadable(localrc)
exec 'source' localrc
endif
" }}}
" vim: foldmethod=marker