forked from rockyzhang24/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.vim
975 lines (758 loc) · 26.9 KB
/
init.vim
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
" Author: Rocky Zhang <[email protected]>
" GitHub: https://github.com/yanzhang0219
" ---------- [ General ] ---------- {{{
set nocompatible
set number
set relativenumber
set cursorline
set cursorlineopt=number,screenline
" set foldcolumn=1
set hidden " Allow buffer switch without saving
set wrap
set autoindent
" set clipboard+=unnamedplus
set scrolloff=5
set sidescrolloff=5
set autoread
set noshowmode
set showcmd
set wildmenu
set wildmode=longest:full,full
set textwidth=80
set colorcolumn=80
set list
set listchars=tab:›\ ,trail:▫,extends:#,nbsp:.,precedes:❮,extends:❯
set fillchars=fold:\ ,eob:\ ,msgsep:‾,
set foldenable
set foldmethod=indent
set foldlevel=99
" set foldmethod=expr
" set foldexpr=nvim_treesitter#foldexpr() " treesitter based folding
set completeopt=menu,menuone,noselect
set ttimeoutlen=50
set timeoutlen=500
set shortmess+=a shortmess+=c shortmess+=I
set inccommand=split
set updatetime=250
set laststatus=2
set showtabline=2
set matchpairs+=<:>
set splitbelow
set splitright
set expandtab
set tabstop=2
set shiftwidth=2
set softtabstop=-1 " use the value of 'shiftwidth'
set shiftround
set hlsearch
set incsearch
set ignorecase
set smartcase
set title
set titlestring=%(%m%)\ %(%{expand(\"%:~\")}%)
set diffopt+=vertical diffopt+=algorithm:patience
set noswapfile
set signcolumn=yes:2
set spelllang=en_us
set pumblend=10
set pumheight=20
set winblend=10
set winminwidth=10
set grepprg=rg\ --vimgrep\ --smart-case\ $*
set grepformat=%f:%l:%c:%m
set breakindent
set breakindentopt=shift:2
set showbreak=↳
set wildignore=*.o,*.obj,*~,*.exe,*.a,*.pdb,*.lib
set wildignore+=*.so,*.dll,*.swp,*.egg,*.jar,*.class,*.pyc,*.pyo,*.bin,*.dex
set wildignore+=*.log,*.pyc,*.sqlite,*.sqlite3,*.min.js,*.min.css,*.tags
set wildignore+=*.zip,*.7z,*.rar,*.gz,*.tar,*.gzip,*.bz2,*.tgz,*.xz
set wildignore+=*.png,*.jpg,*.gif,*.bmp,*.tga,*.pcx,*.ppm,*.img,*.iso
set wildignore+=*.pdf,*.dmg,*.app,*.ipa,*.apk,*.mobi,*.epub
set wildignore+=*.mp4,*.avi,*.flv,*.mov,*.mkv,*.swf,*.swc
set wildignore+=*.ppt,*.pptx,*.doc,*.docx,*.xlt,*.xls,*.xlsx,*.odt,*.wps
set wildignore+=*/.git/*,*/.svn/*,*.DS_Store
set wildignore+=*/node_modules/*,*/nginx_runtime/*,*/build/*,*/logs/*,*/dist/*,*/tmp/*
set confirm
set undofile " presistent undo (use set undodir=... to change the undodir, default is ~/.local/share/nvim/undo)
set nrformats=octal,bin,hex,unsigned,alpha
set sessionoptions+=terminal sessionoptions+=globals
set isfname-==
" Avoid highlighting the last search when sourcing vimrc
exec "nohlsearch"
" Terminal
let g:neoterm_autoscroll = '1'
" Dress up quickfix window
lua require('qf')
" }}}
" ---------- [ Colors ] ---------- {{{
set termguicolors
set background=dark
let g:gruvbox_material_palette = 'original'
let g:gruvbox_material_enable_bold = 1
let g:gruvbox_material_enable_italic = 1
" let g:gruvbox_material_transparent_background = 1
let g:gruvbox_material_visual = 'blue background'
let g:gruvbox_material_diagnostic_virtual_text = 'colored'
let g:gruvbox_material_statusline_style = 'original'
let g:gruvbox_material_better_performance = 1
" function! s:gruvbox_material_custom() abort
" endfunction
" augroup GruvboxMaterialCustom
" autocmd!
" autocmd ColorScheme gruvbox-material call s:gruvbox_material_custom()
" augroup END
colorscheme gruvbox-material
" }}}
" ---------- [ Autocommands ] ---------- {{{
augroup general
autocmd!
" Jump to the position when you last quit
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") && &filetype !~# 'commit' |
\ exe "normal! g'\"" |
\ endif
" Automatically equalize splits when Vim is resized
autocmd VimResized * wincmd =
" Make it not be overwritten by the default setting of neovim
autocmd FileType * set formatoptions-=t formatoptions-=o formatoptions-=r textwidth=80
augroup END
" Highlight selection on yank
augroup highlight_yank
autocmd!
autocmd TextYankPost * silent! lua vim.highlight.on_yank({higroup="Substitute", timeout=300})
augroup END
" Neovim builtin terminal
augroup nvim_terminal
autocmd!
" Automatically start insert mode when enter terminal, and disable line number and indentline
autocmd TermOpen term://* startinsert |
\ setlocal nonumber norelativenumber signcolumn=no |
\ IndentBlanklineDisable
autocmd BufWinEnter,WinEnter term://* startinsert
augroup END
" Automatic toggling relative number
augroup numbertoggle
autocmd!
autocmd BufEnter,FocusGained,InsertLeave,WinEnter * if &nu | set rnu | endif
autocmd BufLeave,FocusLost,InsertEnter,WinLeave * if &nu | set nornu | endif
augroup END
" Disable syntax highlighting for some filetypes if they are too long
augroup syntax_off
autocmd!
autocmd FileType yaml if line('$') > 500 | setlocal syntax=OFF | endif
augroup END
" I manage my dotfiles using a bare repository. To make Vim recognize them and git related plugins
" work on them, the environment variables should be set to indicate the locations of git-dir and
" work-tree when we enter the dotfile buffer. Don't forget to reset them when we enter other buffers,
" otherwise the normal repository will not be recognized.
function! s:SetGitEnv() abort
let cur_file = expand('%')
" Only set the Git env for the buffer containing a real file
if !filereadable(cur_file)
return
endif
let git_dir = expand('~/dotfiles')
let work_tree = expand('~')
let jib = jobstart(["git", "--git-dir", git_dir, "--work-tree", work_tree, "ls-files", "--error-unmatch", cur_file])
let ret = jobwait([jib])[0]
if ret == 0
let $GIT_DIR = git_dir
let $GIT_WORK_TREE = work_tree
else
unlet $GIT_DIR
unlet $GIT_WORK_TREE
endif
endfunction
augroup personal
autocmd!
autocmd BufNewFile,BufRead,BufEnter * call s:SetGitEnv()
augroup END
" }}}
" ---------- [ Commands ] ---------- {{{
" Change indentation for the current buffer
" `:Reindent cur_indent new_indent`, E.g., `:Reindent 2 4` for changing the
" indentation from 2 to 4
command -nargs=+ Reindent call utils#reindent(<f-args>)
" }}}
" ---------- [ Abbreviation ] ---------- {{{
function! s:SetupCommandAbbrs(from, to) abort
exec 'cnoreabbrev <expr> '.a:from
\ .' ((getcmdtype() ==# ":" && getcmdline() ==# "'.a:from.'")'
\ .'? ("'.a:to.'") : ("'.a:from.'"))'
endfunction
call s:SetupCommandAbbrs('T', 'tabedit')
" }}}
" ---------- [ Mappings ] ---------- {{{
" Misc {{{
let mapleader=" "
nnoremap <Space> <NOP>
nnoremap s <NOP>
" The normal `,` is used as a leader key for lsp mappings
nnoremap <Leader>, ,
" Smarter j and k navigation
nnoremap <expr> j v:count ? (v:count > 5 ? "m'" . v:count : '') . 'j' : 'gj'
nnoremap <expr> k v:count ? (v:count > 5 ? "m'" . v:count : '') . 'k' : 'gk'
" Go to the start and end of the line easier
noremap H ^
noremap L $
" Move the selections up and down with corresponding indentation
xnoremap J :m '>+1<CR>gv=gv
xnoremap K :m '<-2<CR>gv=gv
inoremap <M-j> <Esc>:m .+1<CR>==a
inoremap <M-k> <Esc>:m .-2<CR>==a
" Fast insert a place holder
inoremap ,p <++>
" Jump to the next '<++>' and edit it
nnoremap <silent> <Leader><Leader> <Esc>/<++><CR>:nohlsearch<CR>c4l
inoremap <silent> ,f <Esc>/<++><CR>:nohlsearch<CR>"_c4l
" Indent
xnoremap < <gv
xnoremap > >gv
" Delete but not save to a register
nnoremap <Leader>d "_d
xnoremap <Leader>d "_d
nnoremap <Leader>D "_D
nnoremap <Leader>dd "_dd
nnoremap c "_c
xnoremap c "_c
nnoremap C "_C
nnoremap cc "_cc
" Make dot work over visual line selections
xnoremap . :norm.<CR>
" Execute a macro over visual line selections
xnoremap Q :'<,'>:normal @q<CR>
" Clone current paragraph
nnoremap cp yap<S-}>p
" Remove all the trailing whitespaces
nnoremap <silent> _$ :call utils#Preserve("%s/\\s\\+$//e")<CR>;
" Format the whole file
nnoremap <silent> _= :call utils#Preserve("normal gg=G")<CR>;
" When navigating, center the cursor
nnoremap { {zz
nnoremap } }zz
nnoremap ]c ]czz
nnoremap [c [czz
nnoremap [j <C-o>zz
nnoremap ]j <C-i>zz
nnoremap ]s ]szz
nnoremap [s [szz
" Navigation in the argument list
nnoremap <silent> [a :<C-u>previous<CR>
nnoremap <silent> ]a :<C-u>next<CR>
nnoremap <silent> [A :<C-u>first<CR>
nnoremap <silent> ]A :<C-u>last<CR>
" Navigation in the buffer list
nnoremap <silent> [b :<C-u>bprevious<CR>
nnoremap <silent> ]b :<C-u>bnext<CR>
nnoremap <silent> [B :<C-u>bfirst<CR>
nnoremap <silent> ]B :<C-u>blast<CR>
" Navigation in the quickfix list
nnoremap <silent> [q :<C-u>cprevious<CR>zv
nnoremap <silent> ]q :<C-u>cnext<CR>zv
nnoremap <silent> [Q :<C-u>cfirst<CR>zv
nnoremap <silent> ]Q :<C-u>clast<CR>zv
" Navigation in the location list
nnoremap <silent> [l :<C-u>lprevious<CR>zv
nnoremap <silent> ]l :<C-u>lnext<CR>zv
nnoremap <silent> [L :<C-u>lfirst<CR>zv
nnoremap <silent> ]L :<C-u>llast<CR>zv
" Navigate in the tabs
nnoremap <silent> [t :<C-u>tabprevious<CR>
nnoremap <silent> ]t :<C-u>tabnext<CR>
nnoremap <silent> [T :<C-u>tabfirst<CR>
nnoremap <silent> ]T :<C-u>tablast<CR>
" Toggle spell checking
nnoremap <silent> \S :setlocal spell! spelllang=en_us<CR>:set spell?<CR>
" Toggle wrap
nnoremap <silent> \w :set wrap!<CR>:set wrap?<CR>
" Toggle relativenumber
nnoremap <silent> \r :call toggle#ToggleRelativeNum()<CR>
" Toggle quickfix window
nnoremap <silent> \q :call toggle#ToggleQuickFix()<CR>
nnoremap <silent> \l :call toggle#ToggleLocationList()<CR>
" Insert blank lines above or below the current line and preserve the cursor position
nnoremap <expr> [<Space> 'm`' . v:count . 'O<Esc>``'
nnoremap <expr> ]<Space> 'm`' . v:count . 'o<Esc>``'
" Open a line above or below the current line
inoremap <C-CR> <C-o>O
inoremap <S-CR> <C-o>o
" Move the view horizontally when nowrap is set
nnoremap zl 10zl
nnoremap zh 10zh
" }}}
" Copy and past {{{
" Copy
nnoremap Y y$
nnoremap <Leader>y "+y
vnoremap <Leader>y "+y
nnoremap <Leader>Y "+Y
" Copy the entire buffer
nnoremap <silent> y% :<C-u>%y<CR>
nnoremap <silent> Y% :<C-u>%y +<CR>
" Paste and then format
nnoremap p p=`]
" Paste over the selected text
xnoremap p "_c<Esc>p
" Select the last changed (or pasted) text
nnoremap <expr> gp '`[' . strpart(getregtype(), 0, 1) . '`]'
" }}}
" Buffer {{{
" Switch between the current and the last buffer
nnoremap <Backspace> <C-^>
" Delete the current buffer and switch back to the previous one
nnoremap <silent> <Leader>bd :<C-u>bprevious <Bar> bdelete #<CR>
" Delete all the other unmodified buffers
nnoremap <silent> <Leader>bD :call utils#BufsDel()<CR>
" }}}
" Window {{{
" Focus movement around windows
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
" Scroll the other window
nnoremap <M-d> <C-w>w<C-d><C-w>w
nnoremap <M-u> <C-w>w<C-u><C-w>w
inoremap <M-d> <Esc><C-w>w<C-d><C-w>wa
inoremap <M-u> <Esc><C-w>w<C-u><C-w>wa
" Go to the previous window
nnoremap <C-p> <C-w>p
" Create a split window
nnoremap <silent> s- :split<CR>
nnoremap <silent> s\ :vsplit<CR>
" Change vertical to horizontal
nnoremap <Leader>w- <C-w>t<C-w>K
" Change horizontal to vertical
nnoremap <Leader>w\ <C-w>t<C-w>H
" Close all windows except the current (o for only)
nnoremap <Leader>wo <C-w>o
" Move current window to new tab
nnoremap <Leader>wt <C-w>T
" Sizing
nnoremap <Leader><Down> <C-w>5-
nnoremap <Leader><Up> <C-w>5+
nnoremap <Leader><Left> <C-w>5<
nnoremap <Leader><Right> <C-w>5>
" Balance size
nnoremap <Leader>= <C-w>=
" }}}
" Tab {{{
" Open a new tab with an empty window
nnoremap <silent> <Leader>tn :$tabnew<CR>
" Close the current tab
nnoremap <silent> <Leader>tc :tabclose<CR>
" Close all other tabs
nnoremap <silent> <Leader>to :tabonly<CR>
" Move the current tab to the left or right
nnoremap <silent> <Leader>t, :-tabmove<CR>
nnoremap <silent> <Leader>t. :+tabmove<CR>
" }}}
" Searching {{{
" Clean search highlighting
nnoremap <silent> <Leader>/ :<C-U>nohlsearch<C-R>=has('diff')?'<Bar>diffupdate':''<CR><CR><C-L>
" n for searching forward and N for searching backward regardless of / or ?
nnoremap <expr> n (v:searchforward ? 'nzzzv' : 'Nzzzv')
nnoremap <expr> N (v:searchforward ? 'Nzzzv' : 'nzzzv')
" Make * and # search for the current selection
xnoremap * :<C-u>call utils#VSetSearch('/')<CR>/<C-R>=@/<CR><CR>
xnoremap # :<C-u>call utils#VSetSearch('?')<CR>?<C-R>=@/<CR><CR>
" Grep operator (now using vim-grepper instead)
" nnoremap <silent> \g :<C-u>set operatorfunc=utils#GrepOperator<CR>g@
" xnoremap <silent> \g :<C-u>call utils#GrepOperator(visualmode())<CR>
" Find and replace
nnoremap <Leader>r :%s/
xnoremap <Leader>r :s/
" }}}
" Command-line {{{
" Cursor movement in command line (Emacs style)
cnoremap <C-p> <Up>
cnoremap <C-n> <Down>
cnoremap <C-b> <Left>
cnoremap <C-f> <Right>
cnoremap <C-a> <Home>
cnoremap <C-e> <End>
cnoremap ∫ <S-Left>
cnoremap ƒ <S-Right>
" Ctrl-o to open command-line window
set cedit=\<C-o>
" Get the full path of the current file
cnoremap %% <C-R>=fnameescape(expand('%:h')).'/'<cr>
" }}}
" Terminal {{{
" Close the current terminal window
tnoremap <M-c> <C-\><C-n>:quit<CR>
" Close and delete the current terminal buffer
tnoremap <M-d> <C-\><C-n>:bdelete!<CR>
" Back to normal mode in the terminal buffer
tnoremap <Esc> <C-\><C-n>
" Switching between split windows
tnoremap <M-h> <C-\><C-n><C-w>h
tnoremap <M-j> <C-\><C-n><C-w>j
tnoremap <M-k> <C-\><C-n><C-w>k
tnoremap <M-l> <C-\><C-n><C-w>l
" In terminal mode, use <M-r> to simulate <C-r> in insert mode for inserting the content of a register
" Reference: http://vimcasts.org/episodes/neovim-terminal-paste/
tnoremap <expr> <M-r> '<C-\><C-n>"' . nr2char(getchar()) . 'pi'
" }}}
" }}}
" ---------- [ Plugins ] ---------- {{{
" Minpac plugin manager (load minpac on demand)
function! PackInit() abort
packadd minpac
call minpac#init({'progress_open': 'vertical', 'status_open': 'vertical', 'status_auto': 'TRUE'})
call minpac#add('k-takata/minpac', {'type': 'opt'})
call minpac#add('nvim-lua/plenary.nvim') " lua library used by other lua plugins
call minpac#add('tami5/sqlite.lua')
call minpac#add('tpope/vim-commentary')
call minpac#add('tpope/vim-surround')
call minpac#add('RRethy/vim-illuminate')
call minpac#add('RRethy/vim-hexokinase', { 'do': 'make hexokinase' })
call minpac#add('AndrewRadev/splitjoin.vim') " gS and gJ for split and join
call minpac#add('godlygeek/tabular')
call minpac#add('lukas-reineke/indent-blankline.nvim')
call minpac#add('mbbill/undotree')
call minpac#add('mhinz/vim-startify')
call minpac#add('tyru/open-browser.vim')
call minpac#add('yanzhang0219/lualine.nvim')
call minpac#add('akinsho/bufferline.nvim')
call minpac#add('kevinhwang91/nvim-bqf')
call minpac#add('junegunn/fzf', { 'do': 'packloadall! | call fzf#install()' }) " as a filter for bqf
call minpac#add('mhinz/vim-grepper')
call minpac#add('phaazon/hop.nvim')
call minpac#add('kevinhwang91/nvim-hlslens')
call minpac#add('tommcdo/vim-exchange') " cx{motion}, cxx (line), X (visual), cxc (clear), `.` is supported
call minpac#add('kyazdani42/nvim-tree.lua')
call minpac#add('t9md/vim-choosewin')
call minpac#add('lewis6991/foldsigns.nvim')
call minpac#add('gelguy/wilder.nvim', { 'do': 'let &rtp=&rtp | UpdateRemotePlugins' })
call minpac#add('SmiteshP/nvim-gps')
call minpac#add('tversteeg/registers.nvim')
call minpac#add('ThePrimeagen/harpoon')
call minpac#add('akinsho/toggleterm.nvim')
call minpac#add('mg979/vim-visual-multi')
" Telescope
call minpac#add('nvim-telescope/telescope-fzf-native.nvim', { 'do': 'make' }) " sorter for telescope
call minpac#add('nvim-telescope/telescope.nvim')
" Text object
call minpac#add('junegunn/vim-after-object')
call minpac#add('michaeljsmith/vim-indent-object')
call minpac#add('wellle/targets.vim')
" LSP
call minpac#add('neovim/nvim-lspconfig')
call minpac#add('j-hui/fidget.nvim')
call minpac#add('stevearc/aerial.nvim')
call minpac#add('kosayoda/nvim-lightbulb')
call minpac#add('ray-x/lsp_signature.nvim')
" Autocomplete
call minpac#add('hrsh7th/nvim-cmp')
call minpac#add('hrsh7th/cmp-nvim-lsp')
call minpac#add('hrsh7th/cmp-buffer')
call minpac#add('hrsh7th/cmp-path')
call minpac#add('hrsh7th/cmp-cmdline')
call minpac#add('hrsh7th/cmp-nvim-lua')
call minpac#add('onsails/lspkind-nvim')
" Snippets
call minpac#add('L3MON4D3/LuaSnip')
call minpac#add('saadparwaiz1/cmp_luasnip')
" Tree-sitter
call minpac#add('nvim-treesitter/nvim-treesitter', {'do': 'TSUpdate'})
call minpac#add('nvim-treesitter/nvim-treesitter-textobjects')
call minpac#add('JoosepAlviste/nvim-ts-context-commentstring')
call minpac#add('mizlan/iswap.nvim')
call minpac#add('p00f/nvim-ts-rainbow')
call minpac#add('romgrk/nvim-treesitter-context')
" Tags
call minpac#add('ludovicchabant/vim-gutentags')
call minpac#add('skywind3000/gutentags_plus')
" Git
call minpac#add('tpope/vim-fugitive')
call minpac#add('lewis6991/gitsigns.nvim')
" Markdown
call minpac#add('instant-markdown/vim-instant-markdown')
" Icons
call minpac#add('kyazdani42/nvim-web-devicons')
" Color schemes
call minpac#add('folke/tokyonight.nvim')
call minpac#add('dracula/vim')
call minpac#add('sainnhe/gruvbox-material')
endfunction
" }}}
" ---------- [ Plugin config - viml ] ---------- {{{
" choosewin {{{
nmap - <Plug>(choosewin)
let g:choosewin_blink_on_land = 0
let g:choosewin_tabline_replace = 0
" }}}
" fugitive {{{
" Reference: http://vimcasts.org/episodes/fugitive-vim-browsing-the-git-object-database/
augroup fugitiveautocmd
autocmd!
" Use .. to go up to the parent directory if the buffer containing a git blob or tree
autocmd User fugitive
\ if fugitive#buffer().type() =~# '^\%(tree\|blob\)$' |
\ nnoremap <buffer> .. :edit %:h<CR> |
\ endif
" Make bufferlist clean
autocmd BufReadPost fugitive://* set bufhidden=delete
augroup END
" }}}
" gutentags {{{
" Reference: https://zhuanlan.zhihu.com/p/36279445
" Tips: If we need the tags for a project not managed by vcs, we can touch a .root file under the project root folder
let g:gutentags_project_root = ['.git', '.root', '.project']
" Tag file name for ctags
let g:gutentags_ctags_tagfile = '.tags'
" Using both ctags and gtags
let g:gutentags_modules = []
if executable('ctags') " the ctags file generated by gutentags will be prepended to 'tags' option
let g:gutentags_modules += ['ctags']
endif
if executable('gtags-cscope') && executable('gtags')
let g:gutentags_modules += ['gtags_cscope'] "'cscopeprg' will be set to gtags-cscope
endif
" Move tag files out of project dir to avoid being polluted
let g:gutentags_cache_dir = expand('~/.cache/tags')
" Options for ctags
let g:gutentags_ctags_extra_args = ['--fields=+niazS', '--extras=+q']
" Disable connecting gtags database automatically (gutentags_plus will handle the database connection)
let g:gutentags_auto_add_gtags_cscope = 0
" Disable default maps
let g:gutentags_plus_nomap = 1
" Focus to quickfix window after searching
let g:gutentags_plus_switch = 1
" }}}
" harpoon {{{
nnoremap <silent> <Leader>ha :lua require("harpoon.mark").add_file()<CR>
nnoremap <silent> \h :lua require("harpoon.ui").toggle_quick_menu()<CR>
nnoremap <silent> <Leader>1 :lua require("harpoon.ui").nav_file(1)<CR>
nnoremap <silent> <Leader>2 :lua require("harpoon.ui").nav_file(2)<CR>
nnoremap <silent> <Leader>3 :lua require("harpoon.ui").nav_file(3)<CR>
nnoremap <silent> <Leader>4 :lua require("harpoon.ui").nav_file(4)<CR>
" }}}
" iswap {{{
" Use cx to be consistent with vim-exchange
nnoremap <silent> <Leader>cx <Cmd>ISwap<CR>
" }}}
" minpac {{{
function! s:PluginUpdate() abort
" Unset the Git env to avoid git errors caused by minpac#update()
unlet $GIT_DIR
unlet $GIT_WORK_TREE
call minpac#update()
endfunction
command! PluginUpdate source $MYVIMRC | call PackInit() | call s:PluginUpdate()
command! PluginDelete source $MYVIMRC | call PackInit() | call minpac#clean()
call s:SetupCommandAbbrs('pu', 'PluginUpdate')
call s:SetupCommandAbbrs('pd', 'PluginDelete')
" }}}
" vim-hexokinase {{{
let g:Hexokinase_highlighters = ['backgroundfull']
let g:Hexokinase_optInPatterns = 'full_hex,rgb,rgba,hsl,hsla'
" Toggle
nnoremap \c :HexokinaseToggle<CR>
" }}}
" vim-illuminate {{{
" TODO: LSP configuration (https://github.com/RRethy/vim-illuminate#lsp-configuration)
let g:Illuminate_delay = 300
let g:Illuminate_ftblacklist = ['startify', 'qf', 'NvimTree']
highlight selectionHighlightBackground ctermbg=94 guibg=#6E552F
augroup illuminate_augroup
autocmd!
autocmd VimEnter * highlight link illuminatedWord selectionHighlightBackground
augroup END
" }}}
" vim-openbrowser.vim {{{
let g:netrw_nogx = 1
nmap gx <Plug>(openbrowser-smart-search)
vmap gx <Plug>(openbrowser-smart-search)
" ----}}}
" vim-after-object {{{
augroup after-object
autocmd!
autocmd VimEnter * call after_object#enable([']', '['], '=', ':', '-', '#', ' ')
augroup END
" }}}
" vim-grepper {{{
let g:grepper = {}
let g:grepper.dir = 'repo,file'
let g:grepper.repo = ['.git', '.hg', '.svn']
let g:grepper.tools = ['rg', 'git']
let g:grepper.searchreg = 1
let g:grepper.prompt_mapping_tool = '\g'
let g:grepper.rg = {
\ 'grepprg': 'rg -H --no-heading --vimgrep --smart-case',
\ 'grepformat': '%f:%l:%c:%m,%f',
\ 'escape': '\^$.*+?()[]{}|'
\ }
" Operator
nmap gs <Plug>(GrepperOperator)
xmap gs <Plug>(GrepperOperator)
nnoremap <Leader>G :Grepper<CR>
" }}}
" vim-visual-multi {{{
let g:VM_theme = 'iceblue'
let g:VM_maps = {}
let g:VM_maps["Undo"] = 'u'
let g:VM_maps["Redo"] = '<C-r>'
" }}}
" startify {{{
" Make vim-rooter works when a file is opened from startify
let g:startify_change_to_dir = 0
" Filter MRU files
let g:startify_skiplist = ['tmp\..*']
" Devicons
lua << EOF
function _G.webDevIcons(path)
local filename = vim.fn.fnamemodify(path, ':t')
local extension = vim.fn.fnamemodify(path, ':e')
return require'nvim-web-devicons'.get_icon(filename, extension, { default = true })
end
EOF
function! StartifyEntryFormat() abort
return 'v:lua.webDevIcons(absolute_path) . " " . entry_path'
endfunction
" Header
let g:ascii = [
\ ' ▀████▀▄▄ ▄█ ',
\ ' █▀ ▀▀▄▄▄▄▄ ▄▄▀▀█ ',
\ ' ▄ █ ▀▀▀▀▄ ▄▀ ',
\ ' ▄▀ ▀▄ ▀▄ ▀▄▀ ',
\ ' ▄▀ █ █▀ ▄█▀▄ ▄█ ',
\ ' ▀▄ ▀▄ █ ▀██▀ ██▄█ ',
\ ' ▀▄ ▄▀ █ ▄██▄ ▄ ▄ ▀▀ █ ',
\ ' █ ▄▀ █ ▀██▀ ▀▀ ▀▀ ▄▀ ',
\ ' █ █ █ ▄▄ ▄▀ ',
\ ]
let g:startify_custom_header = 'startify#pad(g:ascii + startify#fortune#boxed())'
" Enable cursorline
augroup starity
autocmd User Startified setlocal cursorline
augroup END
" Session management
nnoremap <silent> <Leader>ss :SSave<CR>
nnoremap <silent> <Leader>sl :SLoad<CR>
nnoremap <silent> <Leader>sc :SClose<CR>
nnoremap <silent> <Leader>sd :SDelete<CR>
" }}}
" tabular {{{
nnoremap <Leader>a :Tabularize /
xnoremap <Leader>a :Tabularize /
" Find extra config at ./after/plugin/tabular.vim
" }}}
" targets.vim {{{
" Text object surrounded by any opening and closing characters can be customized
" Ref: https://github.com/wellle/targets.vim#targetsmappingsextend
augroup define_object
autocmd User targets#mappings#user call targets#mappings#extend({
\ 'a': {'argument': [{'o':'(', 'c':')', 's': ','}]}
\ })
augroup END
" }}}
" undotree {{{
let g:undotree_WindowLayout = 2
let g:undotree_ShortIndicators = 1
let g:undotree_SetFocusWhenToggle = 1
let g:undotree_SplitWidth = 30
" Toggle undotree
nnoremap \u :UndotreeToggle<CR>
" }}}
" registers {{{
let g:registers_window_border = "rounded"
" }}}
" wilder {{{
" - Disable by default until pressing Tab, otherwise / and ? conflict with
" vim-visual-multi
" - Keymappings are consitent with nvim-cmp
call wilder#setup({
\ 'modes': [':', '/', '?'],
\ 'enable_cmdline_enter': 0,
\ 'accept_key': '<C-y>',
\ 'reject_key': '<C-e>',
\ })
" A helper function
function! s:shouldDisable(x)
let l:cmd = wilder#cmdline#parse(a:x).cmd
return l:cmd ==# 'Man' || a:x =~# 'Git fetch origin '
endfunction
" Use fuzzy matching instead of substring matching (file completion is supported
" as well)
" NOTE: The completion process for some commands like `Man` take a while and it
" is synchronously, so Neovim will block. We should check this and disable
" wilder for these commands, and Neovim's builtin wildmenu will be used as the
" fallback (Ref: https://github.com/gelguy/wilder.nvim/issues/107)
call wilder#set_option('pipeline', [
\ wilder#branch(
\ [
\ wilder#check({-> getcmdtype() ==# ':'}),
\ {ctx, x -> s:shouldDisable(x) ? v:true : v:false},
\ ],
\ wilder#python_file_finder_pipeline({
\ 'file_command': {_, arg -> arg[0] ==# '.' ? ['rg', '--files', '--hidden'] : ['rg', '--files']},
\ 'dir_command': {_, arg -> arg[0] ==# '.' ? ['fd', '-tf', '-H'] : ['fd', '-tf']},
\ 'filters': ['fuzzy_filter', 'difflib_sorter'],
\ }),
\ wilder#cmdline_pipeline({
\ 'language': 'python',
\ 'fuzzy': 1,
\ }),
\ wilder#python_search_pipeline({
\ 'pattern': wilder#python_fuzzy_pattern(),
\ 'sorter': wilder#python_difflib_sorter(),
\ 'engine': 're2',
\ }),
\ ),
\ ])
" Customize the appearance
" Use popupmenu for command and wildmenu for search
call wilder#set_option('renderer', wilder#renderer_mux({
\ ':': wilder#popupmenu_renderer(wilder#popupmenu_border_theme({
\ 'highlighter': wilder#basic_highlighter(),
\ 'border': 'rounded',
\ 'max_height': 15,
\ 'highlights': {
\ 'border': 'Normal',
\ 'default': 'Normal',
\ 'accent': wilder#make_hl('PopupmenuAccent', 'Normal', [{}, {}, {'foreground': '#f4468f'}]),
\ },
\ 'left': [
\ ' ', wilder#popupmenu_devicons(),
\ ],
\ 'right': [
\ ' ', wilder#popupmenu_scrollbar(),
\ ],
\ })),
\
\ '/': wilder#wildmenu_renderer({
\ 'highlighter': wilder#basic_highlighter(),
\ 'highlights': {
\ 'accent': wilder#make_hl('WildmenuAccent', 'StatusLine', [{}, {}, {'foreground': '#f4468f'}]),
\ },
\ }),
\ }))
" }}}
" }}}
" ---------- [ Plugin config - lua ] ---------- {{{
lua require('plugin_config.aerial')
lua require('plugin_config.bqf')
lua require('plugin_config.bufferline')
lua require('plugin_config.fidget')
lua require('foldsigns').setup()
lua require('plugin_config.gitsigns')
lua require('plugin_config.hop')
lua require('plugin_config.indent')
lua require('plugin_config.lualine')
lua require('plugin_config.luasnip.luasnip-config')
lua require('plugin_config.lightbulb')
lua require('plugin_config.lsp-signature')
lua require('plugin_config.hlslens')
lua require('plugin_config.cmp')
lua require('plugin_config.lsp.lsp-config')
lua require('plugin_config.nvim-ts-rainbow')
lua require('plugin_config.nvim-tree')
lua require('plugin_config.treesitter')
lua require('plugin_config.treesitter-context')
lua require('plugin_config.nvim-gps')
lua require('plugin_config.telescope.telescope-config')
lua require('plugin_config.toggleterm')
" }}}