-
Notifications
You must be signed in to change notification settings - Fork 1
/
.vimrc
997 lines (828 loc) · 29.8 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
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
" vim: foldmethod=marker foldlevel=0
" GENERIC SETTINGS {{{
" =====================
"encoding
set encoding=utf-8
"backspace functionality
set backspace=indent,eol,start
"you might need to install 'vim-gui-common' to enable clipboard support
set clipboard=unnamedplus
set relativenumber
set number
"set foldcolumn=0
"syntax and indentation
if !exists("g:syntax_on")
syntax enable
endif
set tabstop=2 "number of spaces in a tab
set shiftwidth=2 "number of spaces for indent
set softtabstop=2 noexpandtab
set autoindent
set smartindent
set smarttab
set nowrap
"set expandtab "tabs are spaces, aka cancer
"setlocal lcs=tab:>-,trail:-,eol:¬ list! " use list mode mapped to F2 when vim is opened
set updatetime=400
set modeline
" Load bash aliases in here
let $BASH_ENV="~/.bash/aliases.sh"
"search settings
set incsearch
set hlsearch
"split and buffer settings
set splitright
set splitbelow
set hidden "dont close buffers unless ordered to
"scrolling
set scrolloff=4
"swapfiles
set noswapfile
set nowritebackup
set autoread
"display command key pressed
set showcmd
set cmdheight=1
set noshowmode
"autocomplete vim commands
set wildmenu
set wildmode=longest:list,full
set wildignorecase
" enable mouse for resizing window splits
set mouse=n
set guicursor=a:blinkon0
if !has('nvim')
set ttymouse=xterm2
endif
" To diable bell sounds, specially on windows
set noerrorbells visualbell t_vb=
" number text object (integer and float)
" --------------------------------------
" in
function! VisualNumber()
call search('\d\([^0-9\.]\|$\)', 'cW')
normal v
call search('\(^\|[^0-9\.]\d\)', 'becW')
endfunction
xnoremap in :<C-u>call VisualNumber()<CR>
onoremap in :<C-u>normal vin<CR>
" when running command W run w instead (preventing typos)
cnoreabbrev <expr> W ((getcmdtype() is# ':' && getcmdline() is# 'W')?('w'):('W'))
" }}}
" VIM PLUG PLUGINS {{{
" ===================
call plug#begin('~/.vim/plugged')
" COLORSCHEME
Plug '3ximus/gruvbox'
" BASE
if has('nvim')
Plug 'stevearc/oil.nvim'
Plug 'nvim-lualine/lualine.nvim'
Plug 'mfussenegger/nvim-dap'
Plug 'nvim-neotest/nvim-nio'
Plug 'rcarriga/nvim-dap-ui'
Plug 'mxsdev/nvim-dap-vscode-js'
Plug 'microsoft/vscode-js-debug', { 'do': 'npm ci --legacy-peer-deps && npx gulp vsDebugServerBundle && mv dist out' }
else
Plug '3ximus/vim-airline' " my fork switches position of the tabs and splits on tabline
endif
Plug 'scrooloose/nerdtree', { 'on': ['NERDTreeToggle', 'NERDTreeFind'] }
Plug 'Xuyuanp/nerdtree-git-plugin', { 'on': ['NERDTreeToggle', 'NERDTreeFind'] }
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'sjl/gundo.vim', { 'on': 'GundoToggle' }
Plug 'junegunn/vim-peekaboo'
Plug 'jeetsukumaran/vim-markology'
Plug 'wellle/context.vim', { 'on': 'ContextToggle' }
Plug 'markonm/traces.vim' " highlight patterns and ranges in command
Plug 'jeffkreeftmeijer/vim-numbertoggle'
Plug 'benknoble/vim-auto-origami'
Plug 'machakann/vim-highlightedyank'
Plug 'skywind3000/asyncrun.vim'
Plug 'orrors/asynctasks.vim'
" TOOLS
Plug 'tpope/vim-surround'
Plug 'tpope/vim-repeat'
Plug 'tomtom/tcomment_vim'
" Plug 'justinmk/vim-sneak'
Plug 'ggandor/leap.nvim'
Plug 'AndrewRadev/linediff.vim'
Plug 'fidian/hexmode'
Plug 'lambdalisue/vim-suda', { 'on': ['SudaRead', 'SudaWrite'] }
" GIT
Plug 'airblade/vim-gitgutter'
Plug 'tpope/vim-fugitive'
Plug 'stsewd/fzf-checkout.vim', { 'on': ['FZFGBranches', 'FZFGTags'] }
Plug 'godlygeek/tabular', { 'on': ['Tabularize'] }
" COMPLETION
Plug 'neoclide/coc.nvim', { 'branch': 'release' }
Plug 'antoinemadec/coc-fzf'
if exists('$TMUX')
" Plug 'preservim/vimux'
Plug '3ximus/vimux'
endif
" LANGUAGE STUFF
let g:polyglot_disabled = ["sensible"]
" Plug 'sheerun/vim-polyglot' " hasn't been updated in a while and we need a fix
Plug '00dani/vim-polyglot', { 'branch' : 'feature/fix-build' }
Plug 'mattn/emmet-vim'
" DATABASE
Plug 'tpope/vim-dadbod', { 'on': 'DBUI' }
Plug 'kristijanhusak/vim-dadbod-ui', { 'on': 'DBUI' }
Plug 'jidn/vim-dbml', { 'for': 'dbml' }
" OTHER
Plug 'mhinz/vim-startify'
Plug 'SarveshMD/vim-devicons'
Plug 'vim-test/vim-test', { 'on': ['TestNearest', 'TestFile'] }
if v:version >= 800
Plug 'dstein64/vim-startuptime' " Profiler
endif
call plug#end()
" }}}
" COLORSCHEME {{{
" ================
set t_Co=256 "terminal color range
try "try to set the theme as gruvbox
let g:gruvbox_termcolors = 16 "256 colors look really bad
let g:gruvbox_improved_warnings = 1
set background=dark
colorscheme gruvbox
catch /^Vim\%((\a\+)\)\=:E185/
colorscheme darkblue
endtry
" This is now handled on my fork of gruvbox
" makes the background be this color so that when reversed for the airline
" mode foreground it stays FUCKING BLACK!!
" hi Normal ctermbg=236
"trasparent background
" autocmd VimEnter * highlight Normal ctermbg=none
" }}}
" FUNCTIONS {{{
" ==============
"fold function to auto fold entire document based on indent
function! Fold(depth)
let &foldnestmax = a:depth
setlocal foldmethod=indent
endfunction
command! -nargs=1 Fold :call Fold( '<args>' ) "command to use Fold function
"remove trailing whitespaces
function! StripTrailingWhitespace()
if !&binary && &filetype != 'diff'
normal m'
%s/\s\+$//e
normal `'
endif
endfunction
function! ConvertToTabs(tabsize)
let &tabstop = a:tabsize
let l:spaces = repeat(' ', &tabstop)
set noexpandtab
" get one of these to work...
" silent! execute "%s/\(^\s*\)\@<=". l:spaces. "/\t/g"
" :%s/\(^\s*\)\@<=". l:spaces. "/\t/g
:retab!
endfunction
command! -nargs=1 ConvertToTabs :call ConvertToTabs( '<args>' )
function! ConvertToSpaces(spacesize)
let &tabstop = a:spacesize
let &sw = a:spacesize "number of spaces when indenting
set expandtab
%retab!
endfunction
command! -nargs=1 ConvertToSpaces :call ConvertToSpaces( '<args>' )
function! TabSpaceToogle()
if &expandtab
:call ConvertToTabs(&ts)
else
:call ConvertToSpaces(&sw)
endif
endfunction
function! ClearRegisters()
let regs=split('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/-"', '\zs')
for r in regs
call setreg(r, [])
endfor
endfunction
command! -nargs=0 ClearRegisters :call ClearRegisters()
" }}}
" KEYMAPS {{{
" ============
" map leader to space
nnoremap <space> <nop>
let mapleader=" "
" disable F1 help key
map <F1> <Esc>
imap <F1> <Esc>
" change buffers
nmap <C-P> :bp<CR>
nmap <C-N> :bn<CR>
" jumplists remaps
nmap <C-H> <C-O>
nmap <C-L> <C-I>
nmap <C-W>n :tabnext<CR>
nmap <C-W>p :tabprevious<CR>
nmap <C-W>N :tabe %<CR>
" run macro saved to q
nnoremap <leader>q @q
" move line
nnoremap <C-j> :<C-U>m .+1<CR>
nnoremap <C-k> :<C-U>m .-2<CR>
" inoremap <C-j> <Esc>:m .+1<CR>gi
" inoremap <C-k> <Esc>:m .-2<CR>gi
vnoremap <C-j> :m '>+1<CR>gv
vnoremap <C-k> :m '<-2<CR>gv
map Y y$
" fold with fold nest max of 1
nmap zF :call Fold(v:count)<CR>:set foldmethod=manual<CR>
" nmap zM :set foldmethod=marker<CR>
" display line endings and tabs
nnoremap <silent><F2> :<C-U>:execute 'setlocal lcs=tab:>-,trail:-,leadmultispace:\\|' . repeat('\ ', &sw -1) . ',eol:¬ list! list? '<CR>
" toogle paste mode (to prevent indenting when pasting)
set pastetoggle=<F4>
" Idenfigy syntax highlight value under the cursor
map <F10> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
\ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
" start a search for visually selected text
vnoremap // y/\V<C-R>=escape(@",'/\')<CR><CR>
nmap <leader>x :bp<bar>bd #<CR>
" Clear search highlight and close preview window
if has('nvim')
nnoremap <silent> <backspace> :noh<CR>:pc<CR>:cclose<CR>:helpclose<CR>:call CloseGstatus()<CR>:call CocCloseOutline()<CR>
else
nnoremap <silent> <backspace> :noh<CR>:pc<CR>:cclose<CR>:helpclose<CR>:call CloseGstatus()<CR>:call CocCloseOutline()<CR>:call popup_clear(1)<CR>
endif
" remove trailing whitespaces
nmap <leader>s :call StripTrailingWhitespace()<CR>
nnoremap <leader><Tab> :call TabSpaceToogle()<CR>
" save and load view of files
nmap <leader>vs :mkview<CR>
nmap <leader>vl :loadview<CR>
" jump forward and backward in quickfix results
noremap ]q :cnext<CR>
noremap [q :cprevious<CR>
noremap ]c />>>>>>>\\|<<<<<<<<CR>
noremap [c ?>>>>>>>\\|<<<<<<<<CR>
" toogle wrap
nmap <leader>w :setlocal wrap!<CR>:setlocal wrap?<CR>
" recalculate syntax highlight
nmap zz zz:syntax sync fromstart<CR>
" 3 way diff get bindings
nmap gh :diffget //3<CR>
nmap gl :diffget //2<CR>
vnoremap <leader>u] :B !python3 -c 'import sys,urllib.parse;print(urllib.parse.quote(sys.stdin.read()));'<cr>
vnoremap <leader>u[ :B !python3 -c 'import sys,urllib.parse;print(urllib.parse.unquote(sys.stdin.read()));';<cr>
" }}}
" HIGHLIGHT REDEFINITIONS {{{
" ============================
"GitGutter
highlight clear SignColumn
highlight link GitGutterAdd GruvboxGreen
highlight link GitGutterChange GruvboxYellow
highlight link GitGutterDelete GruvboxRed
highlight link GitGutterChangeDelete GruvboxYellow
" Markology
highlight link MarkologyHLl GruvboxYellowBold
highlight link MarkologyHLu GruvboxPurpleBold
highlight link MarkologyHLm GruvboxOrangeBold
" Coc
highlight link CocErrorSign GruvboxRedBold
highlight link CocWarningSign GruvboxYellowBold
highlight link CocInfoSign GruvboxPurpleBold
highlight link CocHintSign GruvboxBlueBold
if !has('gui_running')
" Highlighted Yank
highlight HighlightedyankRegion cterm=reverse gui=reverse
highlight link logLevelInfo GruvboxBlueBold
highlight Error cterm=bold ctermfg=234 ctermbg=9
highlight ErrorMsg cterm=bold ctermfg=234 ctermbg=9
endif
" }}}
" PLUGIN CONFIGURATION {{{
" =========================
"startify
let g:startify_change_to_dir = 0
let g:startify_fortune_use_unicode = 1
" let g:startify_custom_header =
" \ 'startify#pad(startify#fortune#cowsay())'
" let g:ascii = [
" \ ' ⣴⣶⣤⡤⠦⣤⣀⣤⠆ ⣈⣭⣿⣶⣿⣦⣼⣆ ',
" \ ' ⠉⠻⢿⣿⠿⣿⣿⣶⣦⠤⠄⡠⢾⣿⣿⡿⠋⠉⠉⠻⣿⣿⡛⣦ ',
" \ ' ⠈⢿⣿⣟⠦ ⣾⣿⣿⣷ ⠻⠿⢿⣿⣧⣄ ',
" \ ' ⣸⣿⣿⢧ ⢻⠻⣿⣿⣷⣄⣀⠄⠢⣀⡀⠈⠙⠿⠄ ',
" \ ' ⢠⣿⣿⣿⠈ ⣻⣿⣿⣿⣿⣿⣿⣿⣛⣳⣤⣀⣀ ',
" \ ' ⢠⣧⣶⣥⡤⢄ ⣸⣿⣿⠘ ⢀⣴⣿⣿⡿⠛⣿⣿⣧⠈⢿⠿⠟⠛⠻⠿⠄ ',
" \ ' ⣰⣿⣿⠛⠻⣿⣿⡦⢹⣿⣷ ⢊⣿⣿⡏ ⢸⣿⣿⡇ ⢀⣠⣄⣾⠄ ',
" \ ' ⣠⣿⠿⠛ ⢀⣿⣿⣷⠘⢿⣿⣦⡀ ⢸⢿⣿⣿⣄ ⣸⣿⣿⡇⣪⣿⡿⠿⣿⣷⡄ ',
" \ ' ⠙⠃ ⣼⣿⡟ ⠈⠻⣿⣿⣦⣌⡇⠻⣿⣿⣷⣿⣿⣿ ⣿⣿⡇ ⠛⠻⢷⣄ ',
" \ ' ⢻⣿⣿⣄ ⠈⠻⣿⣿⣿⣷⣿⣿⣿⣿⣿⡟ ⠫⢿⣿⡆ ',
" \ ' ⠻⣿⣿⣿⣿⣶⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⡟⢀⣀⣤⣾⡿⠃ ',
" \]
" let g:startify_custom_header =
" \ 'startify#pad(g:ascii + startify#fortune#boxed())'
let g:startify_custom_header =
\ 'startify#pad(startify#fortune#boxed())'
function! s:gitModified()
let files = systemlist('git ls-files -m 2>/dev/null')
return map(files, "{'line': v:val, 'path': v:val}")
endfunction
" same as above, but show untracked files, honouring .gitignore
function! s:gitUntracked()
let files = systemlist('git ls-files -o --exclude-standard 2>/dev/null')
return map(files, "{'line': v:val, 'path': v:val}")
endfunction
let g:startify_lists = [
\ { 'type': 'dir', 'header': [' MRU '. getcwd()] },
\ { 'type': function('s:gitModified'), 'header': [' Git modified']},
\ { 'type': function('s:gitUntracked'), 'header': [' Git untracked']},
\ { 'type': 'files', 'header': [' MRU'] },
\ ]
"NERDTree
let g:NERDTreeDirArrowExpandable = ''
let g:NERDTreeDirArrowCollapsible = ''
let g:NERDTreeMinimalUI=1
let g:NERDTreeCreatePrefix='silent keepalt keepjumps'
let g:NERDTreeShowLineNumbers=1
let g:NERDTreeMinimalMenu=1
let g:NERDTreeHijackNetrw=1
"nerdtree-git
" let g:NERDTreeGitStatusConcealBrackets = 1 " default: 0
" let g:NERDTreeGitStatusShowClean = 1 " default: 0
" let g:NERDTreeGitStatusShowIgnored = 1 " a heavy feature may cost much more time. default: 0
let g:NERDTreeGitStatusIndicatorMapCustom = {
\ 'Modified' :'∗',
\ 'Staged' :'→',
\ 'Untracked' :'%',
\ 'Renamed' :'↻',
\ 'Unmerged' :'═',
\ 'Deleted' :'✘',
\ 'Dirty' :'∗',
\ 'Ignored' :'?',
\ 'Clean' :'✔',
\ 'Unknown' :'?',
\ }
" devicons
" let g:WebDevIconsNerdTreeBeforeGlyphPadding = ''
let g:webdevicons_enable_airline_statusline = 0
let g:webdevicons_enable_airline_tabline = 0
let g:webdevicons_conceal_nerdtree_brackets = 1
let g:DevIconsEnableFoldersOpenClose = 1
let g:DevIconsEnableDistro = 0
" quickr-preview
let g:quickr_preview_position = 'above'
let g:quickr_preview_modifiable = 1
" context.vim
let g:context_add_mappings = 0
let g:context_enabled = 0
"auto-origami (auto manage fold columns)
if exists('&belloff') && &rtp =~ 'vim-auto-origami' && glob("~/.vim/plugged/vim-auto-origami/plugin/auto_origami.vim")!=#""
augroup auto_origami
au!
au CursorHold,BufWinEnter,WinEnter * AutoOrigamiFoldColumn
augroup END
let g:auto_origami_foldcolumn = 1
endif
" gitgutter
let g:gitgutter_sign_added = '┃'
let g:gitgutter_sign_modified = '┃'
let g:gitgutter_sign_modified_removed = '┻'
let g:gitgutter_preview_win_floating = 1
let g:gitgutter_floating_window_options = {
\ 'relative': 'cursor',
\ 'row': 1,
\ 'col': 0,
\ 'width': 42,
\ 'height': &previewheight,
\ 'style': 'minimal',
\ 'border': 'rounded'
\ }
" Gundo
if has('python3')
let g:gundo_prefer_python3 = 1
endif
" Markology
let g:markology_include='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
" Vimux
let g:VimuxPromptString = "$ "
let g:VimuxExpandCommand = 1
"Python syntax highlight
let g:python_highlight_all = 1
let g:python_highlight_indent_errors = 1
let g:python_highlight_space_errors = 0
let g:python_highlight_operators = 0
" vim-go (with vim-polyglot)
let g:go_highlight_function_parameters = 1
let g:go_highlight_extra_types = 1
let g:go_highlight_operators = 1
let g:go_highlight_function_calls = 1
let g:go_highlight_types = 1
let g:go_highlight_fields = 1
let g:go_highlight_build_constraints = 1
let g:go_highlight_generate_tags = 1
let g:go_highlight_variable_declarations = 1
let g:go_highlight_variable_assignments = 1
" vim-svelte-plugin (with vim-polyglot)
let g:vim_svelte_plugin_load_full_syntax = 1
let g:vim_svelte_plugin_use_typescript = 1
let g:vim_svelte_plugin_use_sass = 1
let g:vim_svelte_plugin_has_init_indent = 1
" vim-test
" make test commands execute using dispatch.vim
let test#strategy = 'vimux'
" let test#strategy = 'asyncrun'
" let test#strategy = 'asyncrun_background'
let test#javascript#jest#executable = 'yarn test:watch'
let test#enabled_runners = ["javascript#jest"]
" asynctasks
let g:asynctasks_term_pos = 'tmux'
let g:asynctasks_config_name = '.vim/tasks.ini'
" }}}
" PLUGIN KEYMAPS {{{
" ===================
map <C-t> :NERDTreeToggle<CR>
map <C-f> :NERDTreeFind<CR>
nnoremap U :GundoToggle<CR>
let NERDTreeMapOpenSplit='s'
let NERDTreeMapOpenVSplit='v'
"nertree git
let g:NERDTreeGitStatusMapNextHunk=']h'
let g:NERDTreeGitStatusMapPrevHunk='[h'
" context.vim
nnoremap <F3> :<C-U>ContextToggle<CR>
" gitgutter mappings
omap ih <Plug>(GitGutterTextObjectInnerPending)
omap ah <Plug>(GitGutterTextObjectOuterPending)
xmap ih <Plug>(GitGutterTextObjectInnerVisual)
xmap ah <Plug>(GitGutterTextObjectOuterVisual)
vmap <leader>ha <Plug>(GitGutterStageHunk)
nmap <leader>hu <Plug>(GitGutterUndoHunk)
nmap <leader>hv <Plug>(GitGutterPreviewHunk)
nmap ]h <Plug>(GitGutterNextHunk)
nmap [h <Plug>(GitGutterPrevHunk)
nmap <leader>hf :GitGutterFold<CR>
"leap.nvim
nmap s <Plug>(leap-forward)
nmap S <Plug>(leap-backward)
nmap gs <Plug>(leap-from-window)
"vim sneak
" map f <Plug>Sneak_f
" map F <Plug>Sneak_F
" map t <Plug>Sneak_t
" map T <Plug>Sneak_T
" let g:sneak#label = 1
"fugitive
function! CloseGstatus() abort
for l:winnr in range(1, winnr('$'))
if !empty(getwinvar(l:winnr, 'fugitive_status'))
execute l:winnr.'close'
endif
endfor
endfunction
noremap <silent><leader>gs :Git\|15wincmd_<CR>
noremap <silent><F8> :Git\|15wincmd_<CR>
noremap <leader>gd :Gvdiffsplit!<CR>
noremap <leader>gl :0Gclog<CR>
noremap <leader>gL :G log --graph<CR>
vmap <leader>gl :Gclog<CR>:copen<CR>
noremap <leader>gB :Git blame<CR>
" noremap <leader>gp :AsyncRun -post=Git git push<CR>
noremap <silent><leader>gp :call asyncrun#run('', {'post':'call coc#notify#create(["git push complete"],{"title":" Git ","borderhighlight":"GruvboxGreenBold","highlight":"Normal","timeout":2000,"kind":"info"})'}, 'git push -u')<CR>
" create a popup with git info about the current line
"
if !has('nvim')
nmap <silent><Leader>gm :call setbufvar(winbufnr(popup_atcursor(split(system("git log -n 1 -L " . line(".") . ",+1:" . expand("%:p")), "\n"), { "padding": [1,1,1,1], "pos": "botleft", "wrap": 0 })), "&filetype", "git")<CR>
else
function! ShowGitLogForLine()
let l:git_output = split(system('git log -n 1 -L ' . line(".") . ',+1:' . shellescape(expand("%:p"))), "\n")
if v:shell_error != 0
echohl ErrorMsg
echo "Failed to execute git command:"
echo join(l:git_output, "\n")
echohl None
return
endif
let l:buf = nvim_create_buf(v:false, v:true)
call nvim_buf_set_lines(l:buf, 0, -1, v:false, l:git_output)
call nvim_buf_set_option(l:buf, 'filetype', 'git')
let l:max_line_length = max(map(l:git_output, 'strwidth(v:val)'))
let l:width = min([l:max_line_length + 2, &columns - 4])
let l:height = min([len(l:git_output), &lines])
let l:opts = {
\ 'relative': 'cursor',
\ 'width': l:width,
\ 'height': l:height,
\ 'row': 1,
\ 'col': 1,
\ 'style': 'minimal',
\ 'border': 'rounded',
\ }
call nvim_open_win(l:buf, v:true, l:opts)
endfunction
nnoremap <silent> <Leader>gm :call ShowGitLogForLine()<CR>
endif
" allow typing :git commands instead of :Git
" cnoreabbrev git Git
if !exists(":Gdiffoff")
command Gdiffoff diffoff | q | Gedit
endif
noremap <leader>gD :Gdiffoff<CR>
" Line diff
noremap <leader>D :LinediffReset<CR>
noremap <leader>d :Linediff<CR>
" Emmet mappings
nmap <leader>E :Emmet<space>
let g:user_emmet_leader_key='<C-y>'
let g:user_emmet_expandabbr_key='<C-e>'
let g:user_emmet_mode='inv'
imap <C-e> <plug>(emmet-expand-abbr)
"Vimux
noremap <leader>rc :let g:asynctasks_last = ''<CR>:VimuxPromptCommand<CR>
noremap <expr> <leader>rl g:asynctasks_last != '' ? ':AsyncTaskLast<CR>' : ':VimuxRunLastCommand<CR>'
noremap <leader>rk :VimuxInterruptRunner<CR>
noremap <leader>rq :VimuxCloseRunner<CR>
noremap <leader>ro :VimuxOpenRunner<CR>
noremap <leader>ri :VimuxInspectRunner<CR>
function! VimuxSendSelectedText() range
let [lnum1, col1] = getpos("'<")[1:2]
let [lnum2, col2] = getpos("'>")[1:2]
let lines = getline(lnum1, lnum2)
let lines[-1] = lines[-1][: col2 - (&selection == 'inclusive' ? 1 : 2)]
let lines[0] = lines[0][col1 - 1:]
let selectedText = join(lines, "\n")
call VimuxSendText(selectedText)
endfunction
xnoremap <leader>rr :call VimuxSendSelectedText()<CR>
" Tabularize
if isdirectory(expand("~/.vim/plugged/tabular"))
nmap <leader>a& :Tabularize /&<CR>
vmap <leader>a& :Tabularize /&<CR>
nmap <leader>a= :Tabularize /^[^=]*\zs=<CR>
vmap <leader>a= :Tabularize /^[^=]*\zs=<CR>
nmap <leader>a=> :Tabularize /=><CR>
vmap <leader>a=> :Tabularize /=><CR>
nmap <leader>a: :Tabularize /:<CR>
vmap <leader>a: :Tabularize /:<CR>
nmap <leader>a; :Tabularize /;<CR>
vmap <leader>a; :Tabularize /;<CR>
nmap <leader>a:: :Tabularize /:\zs<CR>
vmap <leader>a:: :Tabularize /:\zs<CR>
nmap <leader>a, :Tabularize /,<CR>
vmap <leader>a, :Tabularize /,<CR>
nmap <leader>a,, :Tabularize /,\zs<CR>
vmap <leader>a,, :Tabularize /,\zs<CR>
nmap <leader>a<Bar> :Tabularize /<Bar><CR>
vmap <leader>a<Bar> :Tabularize /<Bar><CR>
endif
" vim-test
nnoremap <leader>tn :TestNearest<CR>
nnoremap <leader>tf :TestFile<CR>
" dap
if &rtp =~ 'nvim-dap' && &rtp =~ 'nvim-dap-ui' && glob("~/.vim/plugged/nvim-dap")!=#"" && glob("~/.vim/plugged/nvim-dap-ui")!=#""
nmap <F5> :lua require('dap').continue()<CR>
nmap <F6> :lua require('dap.ui.widgets').hover()<CR>
nmap <F7> :lua require('dap').step_into()<CR>
nmap <F8> :lua require('dap').step_over()<CR>
nmap <F9> :lua require('dap').step_out()<CR>
nmap <F10> :lua require('dap').terminate()<CR>
nmap <leader>iu :lua require('dapui').toggle()<CR>
nmap <leader>B :lua require('dap').toggle_breakpoint()<CR>
nmap <leader>bl :lua require('dap').list_breakpoints(); vim.cmd('copen')<CR>
nmap <leader>bC :lua require('dap').clear_breakpoints()<CR>
nmap <leader>bc :lua require('dap').set_breakpoint(vim.fn.input('Break condition: '), nil, nil)<CR>
nmap <leader>bL :lua require('dap').set_breakpoint(nil, nil, vim.fn.input('Log point message: '))<CR>
endif
" }}}
" FZF CONFIGURATION {{{
" =====================
if &rtp =~ 'fzf.vim' && glob("~/.vim/plugged/fzf.vim/plugin/fzf.vim")!=#""
let g:fzf_command_prefix = 'FZF'
if exists('$TMUX')
let g:fzf_layout = { 'tmux': '-p90%,70%' }
else
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.8 , 'border': 'sharp'} }
endif
let g:fzf_history_dir = '~/.local/share/fzf-history'
" CTRL-A CTRL-Q to select all and build quickfix list
function! s:build_quickfix_list(lines)
call setqflist(map(copy(a:lines), '{ "filename": v:val }'))
copen
cc
endfunction
let g:fzf_action = {
\ 'ctrl-q': function('s:build_quickfix_list'),
\ 'ctrl-t': 'tab split',
\ 'ctrl-s': 'split',
\ 'ctrl-v': 'vsplit' }
command! -bang -nargs=* FZFRg
\ call fzf#vim#grep('rg --no-heading --line-number --color=always --smart-case '.shellescape(<q-args>),
\ 1,
\ fzf#vim#with_preview({'options': '--delimiter : --nth 2..'}),
\ <bang>0)
command! -bang -nargs=* FZFRgWithFilenames
\ call fzf#vim#grep('rg --no-heading --line-number --color=always --smart-case '.shellescape(<q-args>),
\ 1,
\ fzf#vim#with_preview(),
\ <bang>0)
nmap <expr> <leader>p fugitive#Head() != '' ? ':FZFGFiles<CR>' : ':FZFFiles<CR>'
nmap <leader>P :FZFFiles<CR>
nmap <leader>l :FZFBuffers<CR>
nmap <F1> :FZFBuffers<CR>
nmap <leader>L :FZFLines<CR>
nmap <leader>f :FZFRg<CR>
nmap <leader>F :FZFRgWithFilenames<space>
nmap <leader>/ :FZFHistory/<CR>
nmap <leader>: :FZFHistory:<CR>
nmap <leader>M :FZFMaps<CR>
nmap <leader>m :FZFMarks<CR>
" coc fzf
let g:coc_fzf_preview_toggle_key = '/'
" let g:coc_fzf_opts = []
let g:coc_fzf_preview = 'up'
" fzf-checkout
let g:fzf_checkout_git_options = '--sort=-committerdate'
noremap <leader>gb :FZFGBranches --locals<CR>
noremap <leader>gt :FZFGTags<CR>
noremap <leader>gC :FZFCommits --pretty=format:'\%C(yellow)\%h\%Creset \%C(auto)\%d\%Creset \%s (\%Cblue\%an\%Creset, \%cr)'<CR>
noremap <leader>gc :FZFBCommits --pretty=format:'%C(yellow)%h%Creset %C(auto)%d%Creset %s (%Cblue%an%Creset, %cr)'<CR>
vmap <leader>gc :FZFBCommits --pretty=format:'%C(yellow)%h%Creset %C(auto)%d%Creset %s (%Cblue%an%Creset, %cr)'<CR>
if glob("~/.vim/plugin/fzf-commands.vim")!=#""
noremap <leader>gv :FZFGitEditBranchFile<CR>
noremap <leader>gV :FZFGitEditCommitFile<CR>
noremap <leader>rt :AsyncTaskFzf<CR>
if exists('$TMUX')
noremap <leader>rp :FZFVimuxPickPane<CR>
endif
if &rtp =~ 'nvim-dap' && &rtp =~ 'nvim-dap-ui' && glob("~/.vim/plugged/nvim-dap")!=#"" && glob("~/.vim/plugged/nvim-dap-ui")!=#""
noremap <leader>ic :FZFDapCommand<CR>
noremap <leader>ib :FZFDapBreakpoints<CR>
noremap <leader>if :FZFDapFrames<CR>
endif
endif
endif
" }}}
" COC CONFIGURATION {{{
" ======================
if !executable('node')
let g:coc_start_at_startup = 0
endif
if &rtp =~ 'coc.nvim' && glob("~/.vim/plugged/coc.nvim/plugin/coc.vim")!=#""
let g:coc_config_home = '~/.vim'
let g:coc_disable_startup_warning = 1
" Coc Extensions
let g:coc_global_extensions = [
\'coc-json',
\'coc-docker',
\'coc-snippets',
\'coc-sh',
\]
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
elseif (coc#rpc#ready())
call CocActionAsync('definitionHover')
else
execute '!' . &keywordprg . " " . expand('<cword>')
endif
endfunction
" Map function and class text objects
" NOTE: Requires 'textDocument.documentSymbol' support from the language server.
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap af <Plug>(coc-funcobj-a)
xmap ic <Plug>(coc-classobj-i)
omap ic <Plug>(coc-classobj-i)
xmap ac <Plug>(coc-classobj-a)
omap ac <Plug>(coc-classobj-a)
" Allow auto import when using C-n and C-p for navigating suggestions
inoremap <silent><expr> <C-n> coc#pum#visible() ? coc#pum#next(1) : "\<C-n>"
inoremap <silent><expr> <C-p> coc#pum#visible() ? coc#pum#prev(1) : "\<C-p>"
inoremap <silent><expr> <down> coc#pum#visible() ? coc#pum#next(0) : "\<down>"
inoremap <silent><expr> <up> coc#pum#visible() ? coc#pum#prev(0) : "\<up>"
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm() : "\<C-g>u\<CR>"
inoremap <silent><expr> <Tab> coc#pum#visible() ? coc#pum#confirm() : "\<C-g>u\<Tab>"
function! CocToggle()
if g:coc_enabled
CocDisable
else
CocEnable
endif
endfunction
command! CocToggle :call CocToggle()
" it actually also closes CocTree with Outgoing and Incoming calls to be more convenient
function! CocCloseOutline()
let winid = coc#window#find('cocViewId', 'OUTLINE')
if winid != -1
call CocAction('hideOutline')
endif
let winid = coc#window#find('cocViewId', 'calls')
if winid != -1
call coc#window#close(winid)
endif
endfunction
function! CocOutlineToggle()
let winid = coc#window#find('cocViewId', 'OUTLINE')
if winid == -1
call CocAction('showOutline')
else
call CocAction('hideOutline')
endif
endfunction
" map ctrl-space to get coc completion
if has('nvim')
inoremap <silent><expr> <c-space> coc#refresh()
else
inoremap <silent><expr> <c-@> coc#refresh()
endif
" Use K to show documentation in preview window.
nnoremap <silent> K :call <SID>show_documentation()<CR>
nnoremap <silent> <leader>K :execute '!' . &keywordprg . " " . expand('<cword>')<CR>
" Use Ctrl l for expanding snippet
imap <C-l> <Plug>(coc-snippets-expand)
" Use `[d` and `]d` to navigate diagnostics
" Use `:cocDiagnostics` to get all diagnostics of current buffer in location list.
nmap <silent> [d <Plug>(coc-diagnostic-prev)
nmap <silent> ]d <Plug>(coc-diagnostic-next)
" GoTo code navigation.
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gD :tab split<CR>:call CocAction('jumpDefinition')<CR>
nmap <silent> gl <Plug>(coc-declaration)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gr <Plug>(coc-references)
nmap <silent> gR <Plug>(coc-rename)
noremap go :call CocActionAsync('runCommand', 'editor.action.organizeImport')<CR>
noremap g= :call CocActionAsync('format')<CR>
nmap <leader>ka <Plug>(coc-codeaction-cursor)
nmap <leader>kA <Plug>(coc-codeaction)
nnoremap <silent><nowait> <leader>kd :<C-u>CocFzfList diagnostics<CR>
nnoremap <silent><nowait> <leader>ke :<C-u>CocFzfList extensions<CR>
nnoremap <silent><nowait> <leader>kc :<C-u>CocFzfList commands<CR>
nnoremap <silent><nowait> <leader>ks :<C-u>CocFzfList snippets<CR>
nnoremap <silent><nowait> <leader>kl :<C-u>CocFzfList outline<CR>
nnoremap <silent><nowait> <leader>ko :<C-u>call CocOutlineToggle()<CR>
nnoremap <silent><nowait> <leader>kt :<C-u>CocToggle<CR>
nnoremap <silent><nowait> <leader>kf :<C-u>call CocAction('showOutgoingCalls')<CR>
nnoremap <silent><nowait> <leader>kr :<C-u>call CocAction('showIncomingCalls')<CR>
endif
" }}}
" GUI SPECIFIC {{{
" =================
if has("gui_running")
colorscheme gruvbox
let g:gruvbox_contrast_dark = 'medium'
let g:gruvbox_contrast_light = 'soft'
set background=dark
set guifont=Terminess\ Nerd\ Font\ Mono\ 13
set linespace=0
set guicursor+=a:blinkon0
"hide toolbar, scrollbar and menubar
set guioptions-=L
set guioptions-=l
set guioptions-=R
set guioptions-=r
set guioptions-=m
set guioptions-=T
set guioptions-=e
endif
" }}}
" FILE SPECIFIC {{{
" ==================
autocmd FileType vim setlocal foldmethod=marker foldlevel=0
" list stashes on fugitive
augroup CustomFugitiveMappings
function ListStashes()
let l:prevheight = &previewheight
set previewheight=4
:Git! --paginate stash list '--pretty=format:%h %as %<(10)%gd %<(76,trunc)%s'
let &previewheight=l:prevheight
endfunction
autocmd!
autocmd FileType fugitive nmap <buffer> czl :call ListStashes()<cr>
augroup END
autocmd FileType python setlocal tabstop=2 shiftwidth=2 softtabstop=2 noexpandtab autoindent "because someone has too much screen space in their eyesight
autocmd FileType python setlocal indentkeys-=<:> " colon will auto indent line in insert mode, remove that behavior
autocmd FileType python setlocal indentkeys-=:
" use dart#dmt or :DartFmt to format the dart file
autocmd FileType dart setlocal formatexpr=dart#fmt()
" must be used from the first line
autocmd FileType json setlocal formatprg=python3\ -m\ json.tool
" add @ completion
autocmd FileType scss setl iskeyword+=@-@
" disable folding on output of dadbod-ui
autocmd FileType dbout setlocal nofoldenable
" }}}
" RUN COMMANDS ON EVENTS {{{
" ===========================
" assumes set noignorecase
if exists('##CmdLineEnter')
augroup dynamic_smartcase
autocmd!
autocmd CmdLineEnter : set ignorecase
autocmd CmdLineLeave : set noignorecase
augroup END
endif
augroup hitablinefill
autocmd!
autocmd User AirlineAfterInit hi airline_tabfill ctermbg=NONE
augroup END
" }}}