-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
630 lines (440 loc) · 14.7 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
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" General Setup
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set expandtab " change indentation behaviour
set shiftwidth=4
set tabstop=4
set softtabstop=4
set autoindent
set smartindent
set path+=**
set encoding=utf-8 " always needed
set fileencoding=utf-8
set nu rnu " show hybrid line numbers
set showcmd " show last command
set nofoldenable " disable folding in markdown files
set cursorline " highlight current line
set wildmenu " visual autocomplete for command menu
filetype indent on " indent according to each filetype
set showmatch " show parenthesis match
set history=500 " how many lines of history VIM remembers
syntax on " syntax highlighting
filetype plugin indent on
set nowrap " wrap text that exceeds screen width
set matchpairs+=<:> " highlight pairs
set hlsearch " highlight matching search patterns
set incsearch " enable incremental search
set ignorecase " ignore matching cases
set nocompatible " open files with vim instead of vi
" set so=7 " set 7 lines to the cursor - when moving vertically
set ruler " always show current position
set cmdheight=1 " height of the command bar
set hid " a buffer becomes hidden when it is abandoned
set magic " for regex search
set updatetime=300
set nobackup " disable backup, swap files, etc.
set nowb
set noswapfile
" set lbr " break line on 100 characters
set tw=100
set guioptions-=r " disable scrollbars
set guioptions-=R
set guioptions-=l
set guioptions-=L
set splitbelow " set terminal to open below
set keywordprg=:Man
set completeopt-=preview " prevent vim from opening buffer when plugin makes suggestions
set spelllang=en_us,de,ru
autocmd BufRead,BufNewFile *.{md,tex} setlocal spell
" set complete+=kspell
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" Mappings
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let mapleader = "," " define the leader
" fast saving
nmap <leader>w :w!<cr>
nmap <leader>q :q!<cr>
nmap <leader>x :x<cr>
nmap <leader>o :only<cr>
" open terminal
" nnoremap <leader>c :term<cr>
" :W sudo saves the file
command! W execute 'w !sudo tee % > /dev/null' <bar>edit!
" map space to search
noremap <space> /
" disable highlight when ,RET is pressed
noremap <silent> <leader><cr> :noh<cr>
" Open files in horizontal split
nnoremap <silent> <Leader>s :call fzf#run({
\ 'down': '40%',
\ 'sink': 'botright split' })<CR>
" Open files in vertical horizontal split
nnoremap <silent> <Leader>v :call fzf#run({
\ 'right': winwidth('.') / 2,
\ 'sink': 'vertical botright split' })<CR>
" easier window navigation (like i3)
noremap <C-j> <C-W>j
noremap <C-k> <C-W>k
noremap <C-h> <C-W>h
noremap <C-l> <C-W>l
" kill all windows
noremap <leader>bo :only<cr>
" close all buffers
noremap <leader>ba :bufdo :Bclose<cr>:tabclose<cr>gT
" navigate between buffers
noremap <leader>l :bnext<cr>
noremap <leader>h :bprevious<cr>
" tab mappings
noremap <leader>tn :tabnew<cr>
noremap <leader>to :tabonly<cr>
noremap <leader>tc :tabclose<cr>
" return to the last edit position when opening files
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
" parenthesis, brackets, quotes
" this is not needed since vim surrounding provides the same
vnoremap $1 <esc>`>a)<esc>`<i(<esc>
vnoremap $2 <esc>`>a]<esc>`<i[<esc>
vnoremap $3 <esc>`>a}<esc>`<i{<esc>
vnoremap $$ <esc>`>a"<esc>`<i"<esc>
vnoremap $q <esc>`>a'<esc>`<i'<esc>
vnoremap $e <esc>`>a"<esc>`<i"<esc>
" filetypes with 2 spaces tab indentation
autocmd Filetype {{java,type}script{,react},html,dart,xml,vue} setlocal expandtab tabstop=2 shiftwidth=2 softtabstop=2
" force rescan syntax highlighting in this files extensions
" autocmd BufEnter *.{js,jsx,ts,tsx} :syntax sync fromstart
" autocmd BufLeave *.{js,jsx,ts,tsx} :syntax sync clear
autocmd BufNewFile, BufRead *.tsx,*.jsx set filetype=typescriptreact
" type ,pu to install all plugins
noremap <leader>pu :PlugInstall<cr>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" Setup Plugger and Plugins
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Automatically install Vim-Plug with all Plugins when first launched
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
" configurations are in EDITING and PROGRAMMING sections
call plug#begin('~/.vim/plugged')
""""""""""""""""""""""""""""""""""""""""""""""
"""
""" EDITING TOOLS
"""
""""""""""""""""""""""""""""""""""""""""""""""
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-surround'
Plug 'ludovicchabant/vim-gutentags'
Plug 'jiangmiao/auto-pairs'
Plug 'junegunn/fzf.vim'
""""""""""""""""""""""""""""""""""""""""""""""
"""
""" THEMES
"""
""""""""""""""""""""""""""""""""""""""""""""""
" Plug 'arcticicestudio/nord-vim'
" Plug 'NLKNguyen/papercolor-theme'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
" Plug 'altercation/vim-colors-solarized'
" Plug 'ayu-theme/ayu-vim'
" Plug 'kaicataldo/material.vim'
Plug 'tomasiser/vim-code-dark'
" Plug 'powerline/powerline'
""""""""""""""""""""""""""""""""""""""""""""""
"""
""" PROGRAMMING LANGUAGES
"""
""""""""""""""""""""""""""""""""""""""""""""""
" Syntax Checker and Auto Completion
Plug 'dense-analysis/ale'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
" Rust
Plug 'rust-lang/rust.vim'
" Markdown
Plug 'plasticboy/vim-markdown'
Plug 'vim-pandoc/vim-pandoc'
Plug 'vim-pandoc/vim-pandoc-syntax'
" Typescript
Plug 'mattn/emmet-vim'
Plug 'sheerun/vim-polyglot'
Plug 'leafgarland/typescript-vim'
" React
Plug 'peitalin/vim-jsx-typescript'
" Vue
Plug 'posva/vim-vue'
" Python
Plug 'vim-scripts/indentpython.vim'
Plug 'nvie/vim-flake8'
Plug 'kh3phr3n/python-syntax'
" Go
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
call plug#end()
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" Theme Config
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" termguicolors don't work in tmux
" let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
" let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
"""""""""""""""""""
"" THEME VARS
"""""""""""""""""""
" This needs some tweaking in your terminal theme as well
" - dark
" - light
" set background=dark
" set termguicolors
" let ayucolor="light" " some themes need to define variables before
" let g:solarized_termcolors=256
let g:material_terminal_italics = 1 " only for material
" Material Themes
" - lighter
" - palenight
" - ocean
" - darker
" let g:material_theme_style = 'palenight'
" Light
" - PaperColor
" - auy
" - solarized
"
" Dark
" - nord
" - material
set t_Co=265
set t_ut=
colorscheme codedark
" Change Colorscheme
nnoremap <silent> <Leader>C :call fzf#run({
\ 'source':
\ map(split(globpath(&rtp, "colors/*.vim"), "\n"),
\ "substitute(fnamemodify(v:val, ':t'), '\\..\\{-}$', '', '')"),
\ 'sink': 'colo',
\ 'options': '+m',
\ 'left': 30
\ })<CR>
"""""""""""""""""""
"" TAB LINE
"""""""""""""""""""
" Either Airline or Lightline is needed
" I have both, since powerline fonts don't work
" on one of my computers
" Some themes take care of these variables for you
" let g:lightline = { 'colorscheme': 'PaperColor' }
" let g:airline_theme='papercolor'
" " air-line
let g:airline_powerline_fonts = 1
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
let g:airline_symbols.space = "\ua0"
let g:airline_theme = 'codedark'
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" MODES & PLUGIN SETUP
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" ALEfix from ALE
let b:ale_fixers = {
\ 'javascript': ['prettier', 'eslint'],
\ 'python': ['yapf', 'black', 'autopep8']
\}
let g:ale_python_auto_pipenv = 1
let g:ale_fix_on_save = 1
nmap <silent> [c <Plug>(ale_previous_wrap)
nmap <silent> ]c <Plug>(ale_next_wrap)
" CoC
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
inoremap <silent><expr> <c-space> coc#refresh()
command! -nargs=0 Prettier :CocCommand prettier.formatFile
" Navigate diagnostics
nmap <silent> [g <Plug>(coc-diagnostics-prev)
nmap <silent> ]g <Plug>(coc-diagnostics-next)
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
nnoremap <leader>cf :CocFix<cr>
nmap <leader>. <Plug>(coc-codeaction)
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim', 'help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
" Highlight references when holding cursor
autocmd CursorHold * silent call CocActionAsync('highlight')
" Formating selected code.
xmap <leader>p <Plug>(coc-format-selected)
nmap <leader>p <Plug>(coc-format-selected)
" Dart
let dart_html_in_string=v:true
let g:dart_style_guide = 2
let g:dart_format_on_save = 1
noremap <leader>df :DartFmt<cr>
" Python PIPENV support
let pipenv_venv_path = system('pipenv --venv')
if shell_error == 0
let venv_path = substitute(pipenv_venv_path, '\n', '', '')
let g:ycm_python_binary_path = venv_path . '/bin/python'
else
let g_ycm_python_binary_path = 'python'
endif
""""""""""""""""""""""""""""""""""
" FZF
""""""""""""""""""""""""""""""""""
" I use fzf to:
" - search for files in git directory
" - all directories recursively
" - navigate through the open buffers
" - open recently opened files
" - create ctags for definition jumps
" - change colorscheme
" - search for pattern in directory (with ripgrep)
noremap <leader>f :GFiles <cr>
noremap <leader>F :Files <cr>
noremap <leader>o :Buffers<cr>
" show files recently edited
command! FZFMru call fzf#run({
\ 'source': v:oldfiles,
\ 'sink': 'e',
\ 'options': '-m -x +s',
\ 'down': '40%'})
" C-c in SQL
let g:ftplugin_sql_omni_key = '<C-j>'
noremap <leader>u :FZFMru<CR>
" CTAGS Setup
let g:fzf_buffers_jump = 1
let g:fzf_tags_command = 'ctags -R'
function! FzfSpellSink(word)
exe 'normal! "_ciw'.a:word
endfunction
function! FzfSpell()
let suggestions = spellsuggest(expand("<cword>"))
return fzf#run({'source': suggestions, 'sink': function("FzfSpellSink"), 'down': 10 })
endfunction
nnoremap z= :call FzfSpell()<CR>
noremap <leader>t :Tags <cr>
command! CD cd %:p:h
" function! s:CompileRun()
" execute 'make ' . expand( '%' )
" execute '!./' . expand( '%:r' )
" endfunction
" command! C call s:CompileRun()
noremap <leader>ce :make %<<cr> :!./%<<cr>
command! PYR execute "!python %"
command! IPY execute "!python -i %"
" FZF.vim now supports this command out of the box
" so this code is no longer needed.
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --column --line-number --hidden --ignore-case --no-heading --color=always '.shellescape(<q-args>), 1,
\ <bang>0 ? fzf#vim#with_preview({'options': '--delimiter : --nth 4..'}, 'up:60%')
\ : fzf#vim#with_preview({'options': '--delimiter : --nth 4..'}, 'right:50%:hidden', '?'),
\ <bang>0)
noremap <C-g> :Rg <CR>
" Rust
let g:rustfmt_autosave = 1
" VIM-GO SETUP
" run :GoBuild or :GoTestCompile based on the go file
function! s:build_go_files()
let l:file = expand('%')
if l:file =~# '^\f\+_test\.go$'
call go#test#Test(0, 1)
elseif l:file =~# '^\f\+\.go$'
call go#cmd#Build(0)
endif
endfunction
autocmd FileType javascript noremap <leader>t :!npm t<cr>
autocmd FileType vue noremap <leader>t :!npm t<cr>
" basic keybindings
autocmd FileType go nmap <leader>b :<C-u>call <SID>build_go_files()<CR>
autocmd FileType go nmap <leader>r <Plug>(go-run)
autocmd FileType go nmap <leader>t <Plug>(go-test)
" toggle :GoCoverage to highlight the code covered by your tests
autocmd FileType go nmap <leader>c <Plug>(go-coverage-toggle)
" autocmd FileType go nmap <leader>cb <Plug>(go-coverage-browser)
autocmd FileType go nmap <leader>a :GoAlternate<cr>
autocmd FileType go nmap <leader>d :GoDecls<cr>
autocmd FileType go nmap <leader>dd :GoDeclsDir<cr>
" this will import missing libs automatically on save
let g:go_fmt_command = "goimports"
" beautify all the code
let g:go_highlight_types=1
" let g:go_highlight_fields=1
let g:go_highlight_functions=1
let g:go_highlight_function_calls=1
let g:go_highlight_operators=1
let g:go_highlight_extra_types=1
let g:go_highlight_build_contraints=1
" Create shortcuts to open alternate (test file) in different tab
autocmd Filetype go command! -bang A call go#alternate#Switch(<bang>0, 'edit')
autocmd Filetype go command! -bang AV call go#alternate#Switch(<bang>0, 'vsplit')
autocmd Filetype go command! -bang AS call go#alternate#Switch(<bang>0, 'split')
autocmd Filetype go command! -bang AT call go#alternate#Switch(<bang>0, 'tabe')
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
" Functions from amix vimrc
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
command! Bclose call <SID>BufcloseCloseIt()
function! <SID>BufcloseCloseIt()
let l:currentBufNum = bufnr("%")
let l:alternateBufNum = bufnr("#")
if buflisted(l:alternateBufNum)
buffer #
else
bnext
endif
if bufnr("%") == l:currentBufNum
new
endif
if buflisted(l:currentBufNum)
execute("bdelete! ".l:currentBufNum)
endif
endfunction
function! CmdLine(str)
call feedkeys(":" . a:str)
endfunction
function! s:tags_sink(line)
let parts = split(a:line, '\t\zs')
let excmd = matchstr(parts[2:], '^.*\ze;"\t')
execute 'silent e' parts[1][:-2]
let [magic, &magic] = [&magic, 0]
execute excmd
let &magic = magic
endfunction
function! s:tags()
if empty(tagfiles())
echohl WarningMsg
echom 'Preparing tags'
echohl None
call system('ctags -R')
endif
call fzf#run({
\ 'source': 'cat '.join(map(tagfiles(), 'fnamemodify(v:val, ":S")')).
\ '| grep -v -a ^!',
\ 'options': '+m -d "\t" --with-nth 1,4.. -n 1 --tiebreak=index',
\ 'down': '40%',
\ 'sink': function('s:tags_sink')})
endfunction
command! Tags call s:tags()