-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
executable file
·642 lines (548 loc) · 17.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
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
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
"""""""""""""
" Defines "
"""""""""""""
let $VIMHOME = expand('$HOME/.vim')
let $VIMCUSTOM = expand('$HOME/.vim/local') " host specific configs
let $VIMBUNDLES = expand('$HOME/.vim/bundles') " bundles location
let s:is_win = has('win64') || has('win32') || has('win16')
let s:is_macos = has('osx') || has('osxdarwin')
let g:bundles = []
if s:is_win
set runtimepath+=$HOME/.vim
endif
"" Functions
" dump command output into a register
function! Dump(cmd)
redir @a
exec printf('silent %s',a:cmd)
redir END
e dumpy
norm "ap
endfunction
" source file if exists
function! s:lsource(filename)
let expfilename = expand(a:filename)
if filereadable(glob(expfilename))
exec 'source ' . expfilename
endif
endfunction
" for manual completion trigger
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~ '\s'
endfunction
""""""""""""""""""""""
" Local pre-config "
""""""""""""""""""""""
call s:lsource($VIMCUSTOM . '/pre.vimrc')
"""""""""""""""""""""""""
" Plugins (vim-plug) "
"""""""""""""""""""""""""
" install vim-plug if not found
if !s:is_win && empty(glob($VIMHOME . '/autoload/plug.vim'))
!wget -P ~/.vim/autoload/
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
" vim-plug does not like this on Windows
" disable before plugs
set noshellslash
" Specify a directory for plugins
" avoid using standard Vim directory names like 'plugin'
call plug#begin('~/.vim/plugged')
" Make sure you use single quotes
"" General
Plug 'qpkorr/vim-bufkill'
Plug 'embear/vim-localvimrc'
Plug 'romainl/vim-qf'
Plug 'sheerun/vim-polyglot'
Plug 'tpope/vim-obsession'
Plug 'tpope/vim-sensible'
"" Code
Plug 'w0rp/ale'
Plug 'tpope/vim-sleuth'
"" Completion
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'SirVer/ultisnips'
Plug 'ludovicchabant/vim-gutentags'
Plug 'honza/vim-snippets'
"" Editing
Plug 'tmsvg/pear-tree'
Plug 'tomtom/tcomment_vim'
Plug 'junegunn/vim-easy-align'
Plug 'easymotion/vim-easymotion'
Plug 'terryma/vim-multiple-cursors'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-unimpaired'
"" Files
Plug 'junegunn/fzf'
Plug 'tweekmonster/fzf-filemru'
Plug 'junegunn/fzf.vim'
Plug 'scrooloose/nerdtree'
"" Git/VCS
Plug 'tpope/vim-fugitive'
Plug 'mhinz/vim-signify'
"" Interface
Plug 'majutsushi/tagbar' " requires ctags
Plug 'bling/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'bling/vim-bufferline'
Plug 'ryanoasis/vim-devicons'
"" Languages
Plug 'Freedzone/kerbovim'
"" Utils
"" Visuals
Plug 'ntpeters/vim-better-whitespace'
Plug 'nathanaelkane/vim-indent-guides'
Plug 'andymass/vim-matchup'
"" Colors
Plug 'tsiemens/vim-aftercolors' " customize color schemes
" schemes
Plug 'romainl/Apprentice'
Plug 'zacanger/angr.vim'
Plug 'gruvbox-community/gruvbox'
Plug 'arcticicestudio/nord-vim'
Plug 'joshdick/onedark.vim'
Plug 'flrnd/plastic.vim'
Plug 'srcery-colors/srcery-vim'
Plug 'tyrannicaltoucan/vim-deep-space'
"" Local plugins
call s:lsource($VIMCUSTOM . '/plugs.vim')
for bundle in g:bundles
call s:lsource($VIMBUNDLES . '/' . bundle . '.plugs')
endfor
"" Initialize plugin system
call plug#end()
""""""""""""""""""
" Autocommands "
""""""""""""""""""
" Neatly highlight left column
augroup hide_fold_col
autocmd!
autocmd ColorScheme * call vimrc#hi_margin_col()
" color is not set until GUI is initialized, need extra autocmd
autocmd GUIEnter * call vimrc#hi_margin_col()
augroup END
" Ignore case for completion only in cmd mode
augroup dynamic_smartcase
autocmd!
autocmd CmdLineEnter : set nosmartcase
autocmd CmdLineLeave : set smartcase
augroup END
""""""""""""""
" Commands "
""""""""""""""
" Get syntax group under cursor
command! GetSynGroup echo "hi<" . synIDattr(synID(line("."),col("."),1),"name")
\ . '> trans<' . synIDattr(synID(line("."),col("."),0),"name")
\ . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"
"""""""""""""
" Visuals "
"""""""""""""
set background=dark " required for dualed colorschemes
set colorcolumn=80 " maximum column width indicator
set cursorline " highlight current line
set foldcolumn=1 " enable fold column for left margin
set laststatus=2 " show status line
set noshowmode " hide active mode name
set shortmess+=c " cleaner completion popup
set showmatch " highlight matching brackets
set showtabline=2 " show tabs
let g:safe_colors_name = "gruvbox"
syntax enable
""""""""""""
" Indent "
""""""""""""
set autoindent " indent whe pasting
set cindent " stricter rules for C programs
set expandtab " spaces instead of TABS in INSERT mode
set linespace=1 " linespace height in pixels
set shiftwidth=4 " indenting is 4 spaces
set smarttab " tab len according to tab options in other places
set softtabstop=4 " number of spaces in tab when editing
""""""""""""""""
" Completion "
""""""""""""""""
set completeopt=menuone,preview,noinsert " for autocomplete plugins
set wildignorecase " ignore case for command mode
set wildmenu " visual autocomplete for command menu
set wildmode=longest:full,full
""""""""""
" Misc "
""""""""""
set confirm " ask confirm instead of failing
set clipboard=unnamedplus " to cp to and paste from system buffer
set encoding=utf-8
set hidden " allow buffer switching without saving
set lazyredraw " redraw only when we need to.
set linebreak " wrap full words, do not split
set modeline " modeline are cool
set number " line numbers
set shellslash " use UNIX like directory separator
set showcmd " show (partial) command in status line
set updatetime=500
" Multi-language support
" https://www.linux.org.ru/forum/development/14418127
set langmap=ФИСВУАПРШОЛДЬТЩЗЙКЫЕГМЦЧНЯЖХЪБЮ\\,ЁЭ;ABCDEFGHIJKLMNOPQRSTUVWXYZ\;{}<>?~\",фисвуапршолдьтщзйкыегмцчняжхъбю.ёэ;abcdefghijklmnopqrstuvwxyz\:[]\\,./`'
set belloff=all
""""""""""""""""""""""
" Search & Replace "
""""""""""""""""""""""
set hlsearch " highlight matches
set ignorecase
set incsearch " search as characters are entered
set smartcase " if uppercase character inputed -> case sensitive
"""""""""""
" Folds "
"""""""""""
set foldenable " enable folding
set foldlevelstart=10 " open most folds by default
set foldnestmax=10 " 10 nested fold max
set foldmethod=indent " fold based on indent level
"""""""""
" GUI "
"""""""""
if has('gui_running')
set guioptions-=T
set guioptions-=e
set winaltkeys=no
" Maximize gvim at start
" if wmctrl is not installed
" set lines=999 columns=999
if s:is_win
autocmd GUIEnter * simalt ~x
set guifont=FuraCode\ NF:h11
set termwintype=conpty " fixes issues with FZF colors in Vim 9+
else
augroup maximizewindow
autocmd!
autocmd VimEnter * call system('wmctrl -i -b add,maximized_vert,maximized_horz -r ' . v:windowid)
augroup END
set guifont=Hack\ Nerd\ Font
endif
endif
"""""""""""""""""""""""
" Platform specific "
"""""""""""""""""""""""
if s:is_win
let $VIMCONFIG = $VIMHOME " Windows uses 'vimfiles' as default, so change
set clipboard=unnamed " copy to and paste from system buffer
endif
""""""""""""""""""
" Key mappings "
""""""""""""""""""
"" General
" Leader to SPACE
let mapleader = " "
let maplocalleader = ","
" Faster command mode
noremap ; :
noremap : ;
" move through wrapped lines
nnoremap j gj
nnoremap k gk
" yank same behavior as D, C
nnoremap Y y$
" dont overwrite register when replacing
xnoremap <expr> p 'pgv"'.v:register.'y'
" turn off search highlight (press enter twice)
nnoremap <silent> <CR> :noh<CR>
" for other languages
noremap № <END>
""" .vimrc
" reload $MYVIMRC
nnoremap <silent> <leader>vs :source $MYVIMRC<CR>
" edit $MYVIMRC
nnoremap <silent> <leader>v :e $MYVIMRC<CR>
""" buffers
" CTRL-i = CTRL-Tab in vim
nnoremap <silent> <C-Tab> :bnext<CR>
nnoremap <silent> <S-Tab> :bprev<CR>
nnoremap <silent> <C-F4> :bw<CR>
nnoremap <silent> <M-w> :bw<CR>
nnoremap <silent> ZBD :bw<CR>
nnoremap <silent> ZBU :bu<CR>
" recently viewed buffer
nnoremap <silent> <M-e> :b#<CR>
""" command mode
cnoremap <C-v> <C-r>*
cnoremap <C-b> <C-a>
" shell life
cnoremap <C-a> <Home>
""" completion
inoremap <expr> <Tab> coc#pum#visible() ? coc#pum#next(0) : pumvisible() ? "<down>" : "<Tab>"
inoremap <expr> <S-Tab> coc#pum#visible() ? coc#pum#prev(0) : pumvisible() ? "<up>" : "<C-d>"
""" files
" write file
nnoremap <C-s> :w<CR>
" reopen file
nnoremap <silent> ZE :e<CR>
" goto file directory
nnoremap <silent> ZD :cd %:p:h<CR>
""" insert mode
" move word back, front
inoremap <C-left> <C-o>B
inoremap <C-right> <C-o>W
" paste from system buffer
inoremap <C-S-v> <C-r>+
" switch case
inoremap <M-u> <C-[>g~iwea
""" useful funcs
" session
nnoremap <F2> :mksession! session.vim<CR>
nnoremap <silent> <C-F2> :source session.vim<CR>
" execute current file
nnoremap <F5> :!./%:r<CR>
" current filename to buf
nnoremap <silent> ZN :let @+=expand('%:p')<CR>
""" windows
" close window
nnoremap <silent> q :close<CR>
" selection
noremap <C-w>l <C-w>L
noremap <C-w>k <C-w>K
noremap <C-w>j <C-w>J
noremap <C-w>h <C-w>H
noremap <C-q> <C-w>w
noremap <M-q> <C-w>W
noremap Q <C-w>p
noremap <silent> <M-h> :wincmd h<CR>
noremap <silent> <M-j> :wincmd j<CR>
noremap <silent> <M-k> :wincmd k<CR>
noremap <silent> <M-l> :wincmd l<CR>
" zoom window
nnoremap <silent> <leader>z :call vimrc#zoom()<CR>
""" other
" macro
nnoremap <leader>q q
" open/closes folds
noremap zz za
noremap za zz
" diff
nnoremap <leader>dp :diffput<CR>
nnoremap <leader>dg :diffget<CR>
" indents
nnoremap <silent> <M->> :><CR>
nnoremap <silent> <M-<> :<<CR>
" quickfix
" check $VIMHOME/ftplugin/qf.vim
"" Plugins
""" ALE
nmap <silent> <C-k> <Plug>(ale_previous_wrap)
nmap <silent> <C-j> <Plug>(ale_next_wrap)
""" better-whitespace
noremap <leader>s :StripWhitespace<CR>
""" bufkill
nnoremap <silent> <C-F4> :BW<CR>
nnoremap <silent> <M-w> :BW<CR>
nnoremap <silent> ZBD :BW<CR>
nnoremap <silent> ZBU :BU<CR>
""" coc.nvim
inoremap <silent><expr> <C-Space>
\ coc#pum#visible() ? coc#pum#next(0) :
\ <SID>check_back_space() ? "\<SPACE>" :
\ coc#refresh()
nmap <leader>cd <Plug>(coc-definition)
nmap <leader>cc <Plug>(coc-declaration)
nmap <leader>ci <Plug>(coc-implementation)
nmap <leader>ct <Plug>(coc-type-definition)
nmap <leader>cr <Plug>(coc-references)
nmap <leader>cn <Plug>(coc-rename)
" scrolling completion float
inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
""" EasyAlign
" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap ga <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)
""" EasyMotion
map <localleader><localleader> <Plug>(easymotion-prefix)
map <leader><leader> <Plug>(easymotion-s)
""" fugitive
noremap <silent> <M-a> :Git blame<CR>
noremap <silent> <M-s> :G<CR>
""" fzf
noremap <silent> <C-p> :FZF<cr>
" fzf history
noremap <silent> <C-h> :History<cr>
" fzf selected word
noremap <silent> <leader>fw :FZF -q <cword><CR>
" fzf buffers
noremap <silent> <leader>fb :Buffers<cr>
""" NERDTree
nnoremap <silent> <leader>n :NERDTreeFocus<cr>
""" pear-tree
imap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm() :
\ pumvisible() ? "<C-y>" : "<Plug>(PearTreeExpand)"
imap <C-c> <Plug>(PearTreeFinishExpansion)
imap <M-n> <Plug>(PearTreeJump)
""" tagbar
noremap <leader>t :Tagbar<CR>
""" UltiSnips
let g:UltiSnipsExpandTrigger = '<c-q>'
""" Unimpaired
nmap <C-S-up> [e
nmap <C-S-down> ]e
vmap <C-S-up> [e
vmap <C-S-down> ]e
""" vim-plug
nnoremap <silent> <F1> :call vimrc#plughelp()<CR>
""" vim-qf
nmap <leader>ee <Plug>(qf_qf_toggle)
nmap <leader>er <Plug>(qf_qf_switch)
""""""""""""""""""""""
" Plugins settings "
""""""""""""""""""""""
"" airline
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
" extensions
let g:airline_extensions = ['ale', 'branch', 'bufferline', 'tabline', 'obsession']
let g:airline#extensions#whitespace#enabled = 0
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#show_splits = 1
let g:airline#extensions#tabline#show_buffers = 1 " enable/disable displaying buffers with a single tab
let g:airline#extensions#tabline#exclude_preview = 1
let g:airline#extensions#tabline#fnamecollapse = 3
let g:airline#extensions#tabline#fnamemod = ':t'
let g:airline#extensions#tabline#formatter = 'unique_tail_improved'
let g:airline#extensions#tabline#show_tab_type = 1
let g:airline#extensions#bufferline#enabled = 1
let g:airline#extensions#bufferline#overwrite_variables = 0
let g:airline#extensions#ale#enabled = 1
let g:airline#extensions#ale#error_symbol = ' '
let g:airline#extensions#ale#warning_symbol = ' '
let airline#extensions#ale#open_lnum_symbol = ' : #'
let airline#extensions#ale#close_lnum_symbol = ''
let g:airline#extensions#obsession#enabled = 1
let g:airline#extensions#obsession#indicator_text = ''
let g:airline_exclude_preview=1
let g:airline_powerline_fonts=1
let g:airline_skip_empty_sections = 1
let g:airline_inactive_collapse=1
let g:airline_left_sep = ''
let g:airline_left_alt_sep = ''
let g:airline_right_sep = ''
let g:airline_right_alt_sep = ''
let g:airline_symbols.branch = ''
let g:airline_symbols.readonly = ''
let g:airline_symbols.linenr = ''
let g:airline_symbols.maxlinenr = ''
"" ALE
let g:ale_python_pylint_executable = 'pylint'
let g:ale_sign_error = ''
let g:ale_sign_warning = ''
let g:ale_sign_info = g:ale_sign_warning
let g:ale_sign_style_error = ''
let g:ale_sign_style_warning = g:ale_sign_style_error
" let g:ale_sign_error = ''
" let g:ale_sign_warning = ''
" let g:ale_sign_info = ''
" let g:ale_sign_style_error = ''
" let g:ale_sign_style_warning = ''
"" better-whitespace
highlight! def link ExtraWhitespace PMenuSel
"" bufferline
let g:bufferline_echo = 0
let g:bufferline_active_buffer_left = ' '
let g:bufferline_active_buffer_right = ''
let g:bufferline_modified = '*'
let g:bufferline_rotate = 2
let g:bufferline_fixed_index = 1 " always first
let g:bufferline_pathshorten = 0
"" coc.nvim
autocmd! CursorHold * silent call CocActionAsync('highlight')
let g:coc_global_extensions = ['coc-sh', 'coc-pyright', 'coc-snippets']
"" denite
" let s:menus = {}
" let s:menus.buffers = {
" \ 'description': 'Buffers operations'
" }
" let s:menus.buffers.commands {
" \ 'decription': 'Example'
" }
" let s:menus.my_commands.command_candidates = [
" \ ['Split the window', 'vnew'],
" \ ['Open zsh menu', 'Denite menu:zsh'],
" \ ]
"" fzf
" Match color scheme
let g:fzf_colors =
\ { 'fg': ['fg', 'Normal'],
\ 'bg': ['bg', 'Normal'],
\ 'hl': ['fg', 'Comment'],
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
\ 'hl+': ['fg', 'Statement'],
\ 'info': ['fg', 'PreProc'],
\ 'border': ['fg', 'Ignore'],
\ 'prompt': ['fg', 'Conditional'],
\ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'],
\ 'spinner': ['fg', 'Label'],
\ 'header': ['fg', 'Comment'] }
let g:fzf_layout = { 'down': '~30%' }
let g:fzf_force_termguicolors = 1
"" indent-guides
let g:indent_guides_enable_on_vim_startup = 1
let g:indent_guides_start_level = 1
let g:indent_guides_guide_size = 1
"" NERDTree
let NERDTreeShowHidden=1
"" pear-tree
let g:pear_tree_smart_openers = 1
let g:pear_tree_smart_closers = 1
let g:pear_tree_smart_backspace = 1
"" UltiSnips
let g:UltiSnipsEditSplit = 'vertical'
let g:UltiSnipsSnippetDirectories = ["UltiSnips", "my-snips"]
"" vim-gutentags
let g:gutentags_enabled=0
let g:gutentags_generate_on_new=0
"" vim-localvimrc
let g:localvimrc_sandbox = 0
let g:localvimrc_ask = 0
"" vim-matchup
let g:matchup_override_vimtex = 1
"" vim-multiple-cursors
let g:multi_cursor_prev_key = '<C-[>'
"" vim-signify
let g:signify_line_highlight = 0
let g:signify_realtime = 0
let g:signify_sign_show_count = 1
let g:signify_sign_show_text = 1
let g:signify_vcs_list = [ 'git' ]
"" vim-sleuth
let g:sleuth_automatic = 0
"""""""""""""""
" Filetypes "
"""""""""""""""
" keep it in the end to overwrite .vimrc bindings
filetype plugin on " filetype-specific settings
filetype plugin indent on " load filetype-specific indent files
"""""""""""""""""""""""
" Local post-config "
"""""""""""""""""""""""
call s:lsource($VIMCUSTOM . '/post.vimrc')
""""""""""""""""""""
" Bundles config "
""""""""""""""""""""
for bundle in g:bundles
call s:lsource($VIMBUNDLES . '/' . bundle . '.vim')
endfor
"""""""""""""""""""""""
" Safe color switch "
"""""""""""""""""""""""
" Fix ugly terminal
autocmd ColorScheme * hi! link Terminal Normal
" Keep it after all configs
" in case variable was overridden
exec "colorscheme " . g:safe_colors_name
""""""""""""""""
" Vimrc fold "
""""""""""""""""
setlocal modelineexpr
" vim:foldmethod=expr:foldexpr=vimrc#folds(v\:lnum):foldtext=vimrc#foldtext()