-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
541 lines (489 loc) · 16.6 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
" Do not run defaults vim, that can enable mouse mode and other stuff
"
" Defaults:
" - /usr/share/vim/vim80/defaults.vim (debian)
let g:skip_defaults_vim=1
runtime! debian.vim
runtime! archlinux.vim
" Load vim-plug
if empty(glob("~/.vim/autoload/plug.vim"))
execute '!curl --create-dirs -fLo ~/.vim/autoload/plug.vim https://raw.github.com/junegunn/vim-plug/master/plug.vim'
endif
"
" Plugins
"
function! BuildYCM(info)
" info is a dictionary with 3 fields
" - name: name of the plugin
" - status: 'installed', 'updated', or 'unchanged'
" - force: set on PlugInstall! or PlugUpdate!
if a:info.status == 'installed' || a:info.force
!./install.py --clangd-completer --rust-completer --go-completer
endif
endfunction
" for YouCompleteMe
let g:plug_timeout=600
call plug#begin('~/.vim/bundle')
Plug 'Valloric/YouCompleteMe', { 'do': function('BuildYCM') }
Plug 'w0rp/ale'
Plug 'junegunn/fzf' " dependency of fzf.vim
Plug 'junegunn/fzf.vim'
Plug 'sunaku/vim-shortcut'
Plug 'szw/vim-tags'
Plug 'vim-scripts/taglist.vim'
Plug 'ciaranm/detectindent'
Plug 'godlygeek/tabular'
Plug 'elzr/vim-json'
Plug 'svermeulen/vim-easyclip'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-unimpaired'
Plug 'tpope/vim-abolish'
Plug 'tpope/vim-dispatch'
Plug 'tpope/vim-commentary'
Plug 'sjl/gundo.vim'
Plug 'itchyny/lightline.vim'
Plug 'tmux-plugins/vim-tmux'
Plug 'pearofducks/ansible-vim' " , { 'do': 'cd ./UltiSnips; ./generate.py' }
Plug 'mmarchini/bpftrace.vim'
Plug 'terryma/vim-multiple-cursors'
Plug 'sakshamgupta05/vim-todo-highlight'
Plug 'mattn/webapi-vim'
Plug 'mattn/vim-gist'
Plug 'crusoexia/vim-monokai'
" Plug 'ericbn/vim-solarized'
Plug 'hashivim/vim-terraform'
Plug 'tmhedberg/SimpylFold' " fold for python
Plug 'rust-lang/rust.vim'
Plug 'pedrohdz/vim-yaml-folds'
call plug#end()
function! PlugLoaded(name)
" FIXME: take into account stridx(&rtp, g:plugs[a:name].dir) >= 0)
" (but now it does not work)
return (
\ has_key(g:plugs, a:name) &&
\ isdirectory(g:plugs[a:name].dir))
endfunction
"
" basic
"
set tags=tags;/
set mouse=
set guicursor=
set number
set hidden
set termencoding=utf-8
set fileencodings=utf8,cp1251
set encoding=utf8
set langmap=ФИСВУАПРШОЛДЬТЩЗЙКЫЕГМЦЧНЯЖ;ABCDEFGHIJKLMNOPQRSTUVWXYZ:,фисвуапршолдьтщзйкыегмцчня;abcdefghijklmnopqrstuvwxyz
set tw=0
set hlsearch
set incsearch
set fileformat=unix
set wildmenu
set laststatus=2
set wcm=<Tab>
set splitbelow
if &term =~ '^screen'
" tmux will send xterm-style keys when its xterm-keys option is on
execute "set <xUp>=\e[1;*A"
execute "set <xDown>=\e[1;*B"
execute "set <xRight>=\e[1;*C"
execute "set <xLeft>=\e[1;*D"
endif
if $TERM =~ '^\(xterm\|tmux\|rxvt\)' && has('nvim')
set termguicolors
endif
syntax enable
try
colorscheme monokai
catch
colorscheme desert
endtry
" Transparent background
highlight Normal guibg=NONE ctermbg=NONE
highlight EndOfBuffer guibg=NONE ctermbg=NONE
" autoread/autowrite
set autowrite
set autoread
if has('nvim')
" Apparently autoread does not always works in nvim, in particular I need
" after SIGSTOP/SIGCONT (C-z/fg) - VimResume.
"
" See also:
" - https://github.com/neovim/neovim/issues/1380
" - https://github.com/neovim/neovim/issues/1936
autocmd FocusGained,BufEnter,CursorHold,CursorHoldI,VimResume *
\ if mode() != 'c' | checktime | endif
" mostly due to trim_trailing_whitespace
let g:editorconfig = v:false
endif
exec "set listchars=tab:\uBB\uBB,trail:\uB7,nbsp:~"
set list
" Make the 81st column stand out
highlight ColorColumn ctermbg=magenta
call matchadd('ColorColumn', '\%81v', 100)
" ignores
set wildignore+=*/.git/**,*/.hg/**,*/.svn/**,*/.cmake**,*/.bld**
set wildignore+=*/build/**,*/__pycache__/**,*/.egg-info/**
set wildignore+=*.exe,*.so,*.dll,*.a,*.o
set wildignore+=*.la,*.lo,*.pc,*.in
set wildignore+=*.sw[poa]
set wildignore+=*.zip,*.rar,*.tgz,*.gz,*.tar,*.zst,*.bgz
set wildignore+=*.pyc,*.whl
" no backup needed
set nobackup
set nowb
set noswapfile
" Open any file with a pre-existing swapfile in readonly mode
augroup NoSimultaneousEdits
autocmd!
autocmd SwapExists * let v:swapchoice = 'o'
autocmd SwapExists * echoerr 'Duplicate edit session (readonly)'
augroup END
" fold
set foldmethod=syntax
set foldenable!
set foldlevel=1000
hi Folded ctermbg=5 " color scheme dark reset can't handle folded info
"
" ale
"
let g:ale_lint_on_text_changed = 'never'
let g:ale_fixers = {
\ '*': [ 'trim_whitespace', ],
\ 'python': [ 'autopep8', 'isort', ],
\ }
let g:ale_linters = {
\ 'cpp': [],
\ 'c': [],
\ }
"
" vim-tags
"
let g:vim_tags_directories = [ ".git/.." ]
let g:vim_tags_auto_generate = 0
let g:vim_tags_project_tags_command = "flock -n /tmp/vim-ctags.lock {CTAGS} -R {OPTIONS} {DIRECTORY} 2>/dev/null"
"
" lightline
"
function! ALEStatus() abort
let l:counts = ale#statusline#Count(bufnr(''))
let l:all_errors = l:counts.error + l:counts.style_error
let l:all_non_errors = l:counts.total - l:all_errors
return l:counts.total == 0 ? 'ALE: OK' : printf(
\ 'ALE: %dW %dE',
\ all_non_errors,
\ all_errors
\)
endfunction
function! YCMStatus() abort
let l:warnings = youcompleteme#GetWarningCount()
let l:errors = youcompleteme#GetErrorCount()
let l:total = warnings + errors
return total == 0 ? 'YCM: OK' : printf(
\ 'YCM: %dW %dE',
\ warnings,
\ errors
\)
endfunction
function! LinterStatus() abort
let l:ale_enabled = exists('b:ale_linted')
if ale_enabled
return ALEStatus()
else
return YCMStatus()
endfunction
function! StatusFileName()
return expand('%:p')
endfunction
let g:lightline = {
\ 'colorscheme': 'seoul256',
\ 'active': {
\ 'left': [
\ [ 'mode', 'paste', 'filename', 'linter', ],
\ ],
\ 'right': [
\ [ 'gitbranch', ],
\ [ 'lineinfo', 'percent', ],
\ [ 'fileformat', 'filetype', ],
\ ],
\ },
\ 'component_function': {
\ 'gitbranch': 'FugitiveHead',
\ 'linter': 'LinterStatus',
\ 'filename': 'StatusFileName',
\ },
\ }
"
" fzf
"
" Command for git grep
" - fzf#vim#grep(command, with_column, [options], [fullscreen])
command! -bang -nargs=* GGrep
\ call fzf#vim#grep(
\ 'git grep --line-number '.shellescape(<q-args>), 0,
\ { 'dir': systemlist('git rev-parse --show-toplevel')[0] }, <bang>0)
noremap <S-F> :GGrep <C-R>=expand("<cword>")<return><return>
"
" vim-shortcut
"
runtime plugin/shortcut.vim
" at least execute map if vim-shortcut is not available
if !exists(':Shortcut')
command! -bang -nargs=+ Shortcut call s:null_shortcut(<q-args>, <bang>0)
function! s:null_shortcut_parse(input) abort
let parts = split(a:input, '\s*\ze\<[nvxsoilct]\?\%(nore\)\?map\>')
if len(parts) < 2
throw 'expected "<description> <map-command>" but got ' . string(a:input)
endif
let [description; rest] = parts
let definition = join(rest, '')
return [description, definition]
endfunction
function! s:null_shortcut(qargs, bang) abort
if !a:bang
let [description, definition] = s:null_shortcut_parse(a:qargs)
execute definition
endif
endfunction
endif
" vim-shortcut bindings
Shortcut show shortcut menu and run chosen shortcut
\ noremap <silent> <leader><leader> :Shortcuts<return>
Shortcut fallback to shortcut menu on partial entry
\ noremap <silent> <leader> :Shortcuts<return>
" fzf bindings
Shortcut Fuzzy search in files
\ noremap <C-P> :GFiles<return>
Shortcut Fuzzy search in buffers
\ noremap <leader>b :Buffers<return>
Shortcut Fuzzy search in history
\ noremap <leader>h :History<return>
Shortcut Fuzzy search in commits (current buffer)
\ noremap <leader>c :BCommits<return>
Shortcut Fuzzy search in commits
\ noremap <leader>C :Commits<return>
Shortcut Fuzzy search in tags (current buffer)
\ noremap <leader>t :BTags<return>
Shortcut Fuzzy search in tags
\ noremap <leader>T :Tags<return>
Shortcut Fuzzy search in lines (current buffer)
\ noremap <leader>l :BLines<return>
Shortcut Fuzzy search in lines
\ noremap <leader>L :Lines<return>
Shortcut Fuzzy search in marks
\ noremap <leader>' :Marks<return>
Shortcut Fuzzy git grep
\ noremap <leader>g :GGrep<return>
Shortcut Explorer noremap <leader>E :Ex<return>
Shortcut Save buffer (force) noremap <leader>w :w!<return>
Shortcut Save buffer and exit (force) noremap <leader>x :x!<return>
Shortcut Quit noremap <leader>q :q<return>
Shortcut Close buffer noremap <leader>d :bd<return>
Shortcut Close buffer (force) noremap <leader>D :bd!<return>
Shortcut Explorer noremap <leader>E :Ex<return>
Shortcut Open new tab noremap <leader>N :tagnew<return>
Shortcut Toggler show numbers noremap <leader>n :set number!<return>
Shortcut Toggler tag/space mode (current buffer)
\ noremap <leader>s :setl noexpandtab! <bar> setl shiftwidth=4 <bar> setl tabstop=4 <bar> setl softtabstop=4<return>
command! -bang -nargs=0 SourceLocal :source $MYVIMRC
command! -bang -nargs=0 SourceSystemWide :source /etc/vimrc
Shortcut! :SourceLocal<return> Reload $MYVIMRC (source)
Shortcut! :SourceSystemWide<return> Reload system-wide vimrc (source)
for i in range(1,9)
execute 'Shortcut go to tab number '. i .' '
\ 'noremap <silent> <leader>'. i .' :tabfirst<bar>'. i .'tabnext<return>'
endfor
" vim-tags
Shortcut! :TagsGenerate<return> Generate tags
Shortcut! :TagsGenerate!<return> Generate tags (force)
" taglist.vim
Shortcut! :TlistToggle<return> Toggle tags (current buffer)
" vim-fugitive
command! -bang -nargs=0 GBlame :Git blame
Shortcut! :GBlame<return> git blame
command! -bang -nargs=0 GAmend :Git commit --amend
Shortcut! :GAmend<return> git commit amend
" git conflict resolution
Shortcut! :Gdiff<return> git diff
Shortcut! :Gvdiff<return> git diff (vertical)
Shortcut! :Gdiff!<return> git diff (3-way)
Shortcut! :Gvdiff!<return> git diff (vertical, 3-way)
Shortcut Update diff noremap <leader>du :diffupdate<return>
" 2-way diff (cherry-pick)
Shortcut diffget noremap <leader>do :diffget<return>
Shortcut diffput noremap <leader>dP :diffput<return>
" 3-way diff (merge)
Shortcut diffget from target noremap <leader>dg :diffget //2<return>
Shortcut diffget from merge noremap <leader>dG :diffget //3<return>
" Plug
Shortcut! :PlugInstall<return> Install plugins
Shortcut! :PlugUpdate<return> Update plugins
Shortcut! :PlugUpdate!<return> Update plugins (force)
Shortcut! :PlugStatus<return> Plugins status
" gundo
Shortcut! :GundoToggle<return> undo tree
" ale
Shortcut! :ALELint<return> Run ALE linters
Shortcut! :ALEInfo<return> Show ALE info (current buffer)
Shortcut! :ALEDetail<return> Show ALE details
Shortcut! :ALEFix<return> Run ALE fixers
Shortcut! :ALEFixSuggest<return> Show ALE suggest fixes
Shortcut! :ALEDisable<return> Disable ALE
Shortcut! :ALEEnable<return> Enable ALE
Shortcut! :ALEToggle<return> Toggle ALE
" vimgist
"
" Do not forget to put "token XXX" into ~/.gist-vim
let g:gist_detect_filetype = 1
let g:gist_open_browser_after_post = 1
let g:gist_per_page_limit = 100
command! -bang -nargs=0 PrivateGist :Gist -p
command! -bang -nargs=0 PublicGist :Gist -P
command! -bang -nargs=0 ListGist :Gist -l
Shortcut! :PrivateGist<return> Private gist
Shortcut! :PublicGist<return> Public gist
Shortcut! :ListGist<return> List gist
Shortcut! :'<,'>Gist<return> Selected gist
let g:cargo_makeprg_params = 'build'
au filetype cpp setlocal makeprg=nice\ -n100\ ninja\ -k0\ -C\ $(git\ rev-parse\ --show-toplevel)/.cmake
au filetype c setlocal makeprg=ninja\ -k0\ -C\ $(git\ rev-parse\ --show-toplevel)/.cmake
" make via vim-dispatch
" NOTE: :Make+makeprg over :Dispatch
" (see https://github.com/tpope/vim-dispatch/issues/41#issuecomment-20555488)
Shortcut [make] noremap <leader>m :Make!<return>
Shortcut [errors] noremap <leader>e :Copen<return>
" ycm/YouCompleteMe
let g:ycm_always_populate_location_list=1
let g:ycm_auto_trigger=1
" Let clangd fully control code completion -- works faster
let g:ycm_clangd_uses_ycmd_caching = 0
" Use installed clangd, not YCM-bundled clangd which doesn't get updates that
" frequently.
let g:ycm_clangd_binary_path = exepath("clangd")
let g:ycm_rust_toolchain_root = fnamemodify(exepath("rust-analyzer"), ":p:h:h")
let g:ycm_auto_hover=''
" Only explicitly via <leader>gD/gd (to preview from the right, not from the
" botton)
set completeopt-=preview
" Preview from the right and adjust the width
command -count YcmShowDocWithSize
\ let g:ph=&previewheight
\ <bar> set previewheight=<count>
\ <bar> <mods> YcmCompleter GetDoc
\ <bar> let &previewheight=g:ph
command -count YcmShowDocImpreciseWithSize
\ let g:ph=&previewheight
\ <bar> set previewheight=<count>
\ <bar> <mods> YcmCompleter GetDocImprecise
\ <bar> let &previewheight=g:ph
Shortcut! :YcmRestartServer<return> YcmRestartServer
Shortcut! :YcmForceCompileAndDiagnostics<return> YcmForceCompileAndDiagnostics
Shortcut! :YcmDiags<return> YcmDiags
Shortcut! :YcmShowDetailedDiagnostic<return> YcmShowDetailedDiagnostic
Shortcut! :YcmDebugInfo<return> YcmDebugInfo
Shortcut! :YcmToggleLogs<return> YcmToggleLogs
" GoTo
Shortcut [ycm GoTo] GoTo (force)
\ noremap <leader>jt :YcmCompleter GoTo<return>
Shortcut [ycm GoTo] GoTo
\ noremap <C-\> :YcmCompleter GoTo<return>
Shortcut [ycm GoToInclude] Looks up the current line for a header and jumps to it
\ noremap <leader>jI :YcmCompleter GoToInclude<return>
Shortcut [ycm GoToDeclaration] Looks up the symbol under the cursor and jumps to its declaration
\ noremap <leader>jd :YcmCompleter GoToDeclaration<return>
Shortcut [ycm GoToDefinition] Looks up the symbol under the cursor and jumps to its definition
\ noremap <leader>jD :YcmCompleter GoToDefinition<return>
Shortcut [ycm GoToCallers]
\ noremap <leader>jc :YcmCompleter GoToCallers<return>
Shortcut [ycm GoToCallees]
\ noremap <leader>jC :YcmCompleter GoToCallees<return>
Shortcut [ycm GoToAlternateFile (header/module)]
\ noremap <leader>ja :YcmCompleter GoToAlternateFile<return>
" Semantic Information Commands
Shortcut [ycm GetType] Echos the type of the variable or method under the cursor
\ noremap <leader>gT :YcmCompleter GetType<return>
Shortcut [ycm GetTypeImprecise] Echos the type of the variable or method under the cursor (force)
\ noremap <leader>gt :YcmCompleter GetTypeImprecise<return>
Shortcut [ycm GetParent] Echos the semantic parent of the point under the cursor
\ noremap <leader>gp :YcmCompleter GetParent<return>
Shortcut [ycm GetDoc] Displays the doc (force)
\ noremap <leader>gd :rightbelow vertical 80YcmShowDocWithSize<return>
Shortcut [ycm GetDocImprecise] Displays the doc
\ noremap <leader>gD :rightbelow vertical 80YcmShowDocImpreciseWithSize<return>
Shortcut [ycm] FixIt
\ noremap <leader>F :YcmCompleter FixIt<return>
Shortcut [ycm] Rename
\ noremap <leader>r :exe 'YcmCompleter RefactorRename '.input('refactor \"'.expand('<cword>').'\" to:')<return>
" TODO: make shortcuts works from menu and not only via <leader>
" syntax
command! -bang -nargs=0 ShowSyntaxList :syntax list
Shortcut! :ShowSyntaxList<return> Show syntax list
set synmaxcol=256
set pastetoggle=<leader>p
"
" detectindent
"
let g:detectindent_preferred_indent=4
let g:detectindent_max_lines_to_analyse=1024
let g:detectindent_preferred_expandtab=1
let g:is_bash=1
" Default indent is with spaces
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
" Always Tab for Makefile
au FileType make set noexpandtab
au FileType make let detectindent_preferred_expandtab=0
"
" vim-todo-highlight
"
let g:todo_highlight_config = {
\ 'REVIEW': {},
\ 'NOTE': {
\ 'gui_fg_color': '#ffffff',
\ 'gui_bg_color': '#ffbd2a',
\ 'cterm_fg_color': 'white',
\ 'cterm_bg_color': '214'
\ }
\ }
"
" filetype plugin
"
filetype plugin on
filetype plugin indent on
autocmd BufEnter * if &filetype == "" | setlocal ft=sh | endif
if PlugLoaded('detectindent')
autocmd BufReadPost * :DetectIndent
endif
"
" bindings (other shortcut)
"
noremap <F1> :setlocal spell!<return>
inoremap <F1> <C-\><C-O>:setlocal spell!<return>
nnoremap <C-a> <nop>
nnoremap <C-x> <nop>
" < & > - indent
vmap < <gv
vmap > >gv
" tab movements
map <C-left> :tabprev<return>
map <C-right> :tabnext<return>
" toggle *pointer*
noremap <C-C> :set cursorline! <bar> set cursorcolumn!<return>
inoremap <C-C> <C-O>:set cursorline! <bar> set cursorcolumn!<return>
" clang-format
if has('python')
map <C-K> :pyf /usr/share/clang/clang-format.py<return>
imap <C-K> <c-o>:pyf /usr/share/clang/clang-format.py<return>
Shortcut clang-format
\ noremap <leader>k :pyf /usr/share/clang/clang-format.py<return>
elseif has('python3')
map <C-K> :py3f /usr/share/clang/clang-format.py<return>
imap <C-K> <c-o>:py3f /usr/share/clang/clang-format.py<return>
Shortcut clang-format
\ noremap <leader>k :py3f /usr/share/clang/clang-format.py<return>
endif