-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc-nvim
executable file
·1940 lines (1753 loc) · 86.2 KB
/
vimrc-nvim
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
998
999
1000
" https://vimjc.com/vim-commands-and-vim-mapping-conf.html 常用Vim命令及实用Vim按键映射配置
" nnoremap <F5> :update<CR>:source %<CR>
" nnoremap <leader><F5> :update<CR>:source %<CR>
" [vim-dispatch] 异步执行+语法糖和命令 :term make异步调用make
" makeprg 用于设置执行:make时使用那个命令行程序 --> term make
" errorformat 可以定义一些便于识别的错误格式
" compiler 用于指定其他的编译器插件,它也会修改编译器的输出格式
"autocmd FileType cpp set makeprg="g++ -Wall -Wextra -std=c++11 ". expand("%") . " && ./a.out"
"" autocmd FileType c set makeprg="gcc\ -Wall\ -o\ %<\ %"<CR>
autocmd FileType lua set makeprg="lua ".expand("%")
autocmd FileType python set makeprg="python ".expand("%")
autocmd FileType bash set makeprg="bash ".expand("%")
autocmd FileType sh set makeprg="bash ".expand("%")
autocmd FileType perl set makeprg=perl\ -c\ %\ $* errorformat=%f:%l:%m
" augroup END
" autocmd FileType c set makeprg="gcc\ '%'\ -o\ '%:r'\ -std=gnu99\ -Wall"
autocmd FileType python set makeprg=echo\ OK
autocmd FileType c set makeprg=gcc\ -g\ -Wall\ -Wno-sign-compare\ %
" autocmd FileType cpp set makeprg=g++\ -g\ -Wall\ -Wno-sign-compare\ %
" autocmd Filetype sh set equalprg=shfmt\ -i\ 2
autocmd Filetype python set equalprg=yapf
autocmd Filetype javascript,javascript.jsx set equalprg=prettier\ --parser=babylon
autocmd Filetype json set equalprg=prettier\ --parser=json
autocmd Filetype css,scss,less set equalprg=prettier\ --parser=css
autocmd Filetype yaml set equalprg=prettier\ --parser=yaml
autocmd Filetype markdown set equalprg=tidy-markdown
autocmd Filetype c,cpp set equalprg=clang-format\ --style=Google
autocmd FileType cpp,java setlocal equalprg=astyle\ -A1sCSNLYpHUEk1xjcn
autocmd Filetype html set equalprg=html-beautify\ --indent-size=2\ --no-preserve-newlines\ -
autocmd Filetype xml set equalprg=xmllint\ --format\ -
autocmd BufEnter * lcd %:p:h " change to directory of current file automatically
nnoremap <c-x><c-o> <c-o><CR> " termial in windows
nnoremap <c-x><c-i> <c-i><CR> " termial in windows
autocmd BufWritePost *tmux.conf !tmux source-file %
" Hex read
nmap <Leader>hr :%!xxd<CR> :set filetype=xxd<CR>
" Hex write
nmap <Leader>hw :%!xxd -r<CR> :set binary<CR> :set filetype=<CR>
nmap <leader>g* :noautocmd vimgrep -n /<C-R><C-W>/j **/*<CR>:cwin<CR> # 搜索光标下word单词 递归目录
nmap <leader>g# :noautocmd vimgrep -n /<C-R><C-W>/j * <CR>:cwin<CR> # 搜索光标下word单词 本目录
nmap <leader>g% :noautocmd vimgrep -n /<C-R><C-W>/j % <CR>:cwin<CR> # 搜索光标下word单词 本文件
nmap <leader>sf :noautocmd vimgrep -n /\<<C-R><C-W>\>/j % <CR>:cwin<CR> # 搜索光标下word单词 递归目录
nmap <leader>sd :noautocmd vimgrep -n /\<<C-R><C-W>\>/j * <CR>:cwin<CR> # 搜索光标下word单词 本目录
nmap <leader>sr :noautocmd vimgrep -n /\<<C-R><C-W>\>/j **/*<CR>:cwin<CR> # 搜索光标下word单词 本文件
nmap <leader>ss :noautocmd vimgrep -n /<C-r>//j **/*<CR>:cwin<CR> # 搜索刚搜索单词
nmap <leader>sF :noautocmd vimgrep -n /\<<C-R><C-A>\>/j % <CR>:cwin<CR> # 搜索光标下word单词 递归目录
nmap <leader>sD :noautocmd vimgrep -n /\<<C-R><C-A>\>/j * <CR>:cwin<CR> # 搜索光标下word单词 本目录
nmap <leader>sR :noautocmd vimgrep -n /\<<C-R><C-A>\>/j **/*<CR>:cwin<CR> # 搜索光标下word单词 本文件
" :argdo
" :bufdo
" :tabdo
" :windo
" :map <c-x>; :map <c-a>; :map <c-c>; :map <c-\>; :map \;
let g:which_key_map = {}
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" recently used or append
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
nnoremap <Tab> %
vnoremap <Tab> %
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" F1-F12 显示方式 和 <Leader>F1-F12 插件窗口 快捷键 F5编译/执行 <Leader>F5执行
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""" F1-F12 快捷键
" 代码显示
nnoremap <F2> :set nu! nu?<CR>
nnoremap <F3> :set list! list?<CR>
nnoremap <F4> :set wrap! wrap?<CR>
" :set makeprg=gcc\ -Wall\ -omain\ main.c
" :make -> :compiler! helloworld -> compiler/helloworld.vim
augroup ccompile
autocmd Filetype c nnoremap <F5> <Esc>:w<CR>:!gcc % -std=gnu99 -g -o %< -pthread -lrt -lm -O1 <CR>
autocmd Filetype cpp nnoremap <F5> <Esc>:w<CR>:!g++ % -std=c++11 -g -o %< -pthread -lrt -lm -O1 <CR>
autocmd Filetype python nnoremap <F5> <Esc>:w<CR>:!ipython % <CR>
autocmd Filetype java nnoremap <F5> <Esc>:w<CR>:!javac % <CR>
autocmd Filetype sh nnoremap <F5> <Esc>:w<CR>:term bash % <CR>
autocmd Filetype perl nnoremap <F5> <Esc>:w<CR>:term perl % <CR>
autocmd Filetype lua nnoremap <F5> <Esc>:w<CR>:term lua % <CR>
autocmd Filetype js nnoremap <F5> <Esc>:w<CR>:term node % <CR>
autocmd Filetype vim nnoremap <F5> <Esc>:w<CR>:source % <CR>
augroup END
augroup crun
autocmd Filetype c nnoremap <leader><F5> <Esc>:!gcc % -std=gnu99 -g -o %< -pthread -lrt -lm -O1 <CR>:! ./%< <CR>
autocmd Filetype cpp nnoremap <leader><F5> <Esc>:!g++ % -std=c++11 -g -o %< -pthread -lrt -lm -O1 <CR>:! ./%< <CR>
autocmd Filetype java nnoremap <leader><F5> <ESC>:!javac % <CR>:java %< <CR>
autocmd Filetype sh nnoremap <leader><F5> <Esc>:w<CR>:vert term bash % <CR>
autocmd Filetype perl nnoremap <leader><F5> <Esc>:w<CR>:vert terminal perl % <CR>
autocmd Filetype lua nnoremap <leader><F5> <Esc>:w<CR>:vert term lua % <CR>
autocmd Filetype js nnoremap <leader><F5> <Esc>:w<CR>:vert term node % <CR>
autocmd Filetype vim nnoremap <leader><F5> <Esc>:w<CR>:source % <CR>
augroup END
if filereadable("tags")
set tags=./tags;
" set tags+=/usr/include/tags
else
set tags=./tags;,tags
" set tags+=/usr/include/tags
endif
if filereadable(".tags")
set tags=./.tags;
" set tags+=/usr/include/tags
else
set tags=./.tags;,.tags
" set tags+=/usr/include/tags
endif
" redefine F1-F12 hotkey
if filereadable(".vimenv")
source ./.vimenv
nnoremap <c-x><c-k> :CMakeHelpPopup <C-R>=expand("<cword>")<CR><CR> "<c-c> quit popup
endif
" +[-ljson-c] + [-O1 -fsanitize=address -fno-omit-frame-pointer]
" nnoremap <F5> <Esc>:w<CR>:!clang % -std=gnu99 -ljson-c -g -o %< -pthread -lrt -lm -O1 -fsanitize=address -fno-omit-frame-pointer <CR>
" nnoremap <leader><F5> <Esc>:!clang % -std=gnu99 -ljson-c -g -o %< -pthread -lrt -lm -O1 -fsanitize=address -fno-omit-frame-pointer <CR>:! ./%< <CR>
augroup snippets
autocmd Filetype text nnoremap <c-a>k <Esc>:vs ~/.vim/plugged/vim-snippets/snippets/_.snippets<CR><CR>
autocmd Filetype c nnoremap <c-a>k <Esc>:vs ~/.vim/plugged/vim-snippets/snippets/c.snippets<CR><CR>
autocmd Filetype cpp nnoremap <c-a>k <Esc>:vs ~/.vim/plugged/vim-snippets/snippets/cpp.snippets<CR><CR>
autocmd Filetype java nnoremap <c-a>k <Esc>:vs ~/.vim/plugged/vim-snippets/snippets/java.snippets<CR><CR>
autocmd Filetype sh nnoremap <c-a>k <Esc>:vs ~/.vim/plugged/vim-snippets/snippets/sh.snippets<CR><CR>
autocmd Filetype perl nnoremap <c-a>k <Esc>:vs ~/.vim/plugged/vim-snippets/snippets/perl.snippets<CR><CR>
autocmd Filetype lua nnoremap <c-a>k <Esc>:vs ~/.vim/plugged/vim-snippets/snippets/lua.snippets<CR><CR>
autocmd Filetype vim nnoremap <c-a>k <Esc>:vs ~/.vim/plugged/vim-snippets/snippets/vim.snippets<CR><CR>
autocmd Filetype cmake nnoremap <c-a>k <Esc>:vs ~/.vim/plugged/vim-snippets/snippets/cmake.snippets<CR><CR>
autocmd Filetype text nnoremap <c-a><c-k> <Esc>:vs ~/.vim/vim-mysnippet<CR><CR>
autocmd Filetype c nnoremap <c-a><c-k> <Esc>:vs ~/.vim/vim-mysnippet/c<CR><CR>
autocmd Filetype perl nnoremap <c-a><c-k> <Esc>:vs ~/.vim/vim-mysnippet/perl<CR><CR>
autocmd Filetype sh nnoremap <c-a><c-k> <Esc>:vs ~/.vim/vim-mysnippet/sh<CR><CR>
autocmd Filetype cmake nnoremap <c-a><c-k> <Esc>:vs ~/.vim/vim-mysnippet/cmake<CR><CR>
autocmd Filetype lua nnoremap <c-a><c-k> <Esc>:vs ~/.vim/vim-mysnippet/lua<CR><CR>
autocmd Filetype make nnoremap <c-a><c-k> <Esc>:vs ~/.vim/vim-mysnippet/make<CR><CR>
autocmd Filetype c nnoremap <c-x>k <Esc>:Man <C-R>=expand("<cword>")<CR><CR>
autocmd Filetype c nnoremap <c-x><c-k> <Esc>:Vman <C-R>=expand("<cword>")<CR><CR>
autocmd Filetype perl nnoremap <c-x>k :Perldoc<CR>
autocmd Filetype perl nnoremap <c-x><c-k> :Perldoc<CR>
autocmd Filetype cmake nnoremap <c-x>k <Esc>:CMakeHelpPopup <C-R>=expand("<cword>")<CR><CR>
autocmd Filetype cmake nnoremap <c-x><c-k> <Esc>:CMakeHelpPopup <C-R>=expand("<cword>")<CR><CR>
augroup END
" 代码格式化
augroup format
autocmd Filetype c nnoremap <F6> :FixWhitespace<CR>:!dos2unix %<CR>:!indent -kr -i4 -ts4 -sob -ss -sc -npsl -pcs -bs --ignore-newlines -l200 -nut -npro -brf %<CR>:%s/\r//ga<CR>
autocmd Filetype perl nnoremap <F6> :FixWhitespace<CR>:!dos2unix %<CR>:!perltidy -i=4 -et=4 -ndsm -st -ce -bar -nola -l=220 %<CR>:%s/\r//ga<CR>
autocmd Filetype cpp nnoremap <F6> :FixWhitespace<CR>:!dos2unix %<CR>:%s/\r//ga<CR>
autocmd Filetype sh nnoremap <F6> :FixWhitespace<CR>:!dos2unix %<CR>:!shfmt -l -w -i 2 -ci %<CR>:%s/\r//ga<CR>
augroup END
nnoremap <F6> :FixWhitespace<CR>:Autoformat<CR>:w!<CR>:!dos2unix %<CR>
" 静态代码扫描
augroup format
" autocmd Filetype c nnoremap <F7> :new | read !cppcheck --std=c99 --enable=warning,style -v #<CR>
" autocmd Filetype sh nnoremap <F7> :new | read !shellcheck #<CR>
autocmd Filetype perl nnoremap <F7> :new | read !perlcritic #<CR>
augroup END
nnoremap <F7> :SyntasticToggleMode<CR><CR>
nnoremap <F8> :edit! %<CR>
nnoremap <F9> :set paste! paste?<CR>
nnoremap <F10> :set hlsearch! hlsearch?<CR>
nnoremap <F11> :PreviewTag<cr>
inoremap <F11> <c-o>:PreviewTag<cr>
set background=dark " Assume a dark background
" Allow to trigger background
function! ToggleBG()
let s:tbg = &background
" Inversion
if s:tbg == "dark"
set background=light
else
set background=dark
endif
endfunction
noremap <F12> :call ToggleBG()<CR>
" 自说明帮助
nnoremap <leader><F1> :e $MYVIMRC<CR>
" 扩展窗口
nnoremap <leader><F2> :TlistToggle<CR>
nnoremap <leader><F3> :NERDTreeRefreshRoot<CR>:NERDTreeToggle<CR>
nnoremap <leader><F4> :CtrlPMixed<CR>
nnoremap <leader><F6> :AV<CR>
nnoremap <leader><F7> :MundoToggle<CR>
nnoremap <leader><F8> :TigOpenCurrentFile<CR>
nnoremap <leader><F9> :TigOpenProjectRootDir<CR>
nnoremap <leader><F10> :vert terminal<CR>
nnoremap <leader><F11> <Esc>:w<CR>:!ctags --language-force=sh % <CR>:set ft=sh<CR>:set tags=./tags<CR>
nnoremap <silent> <c-x><c-h> :WhichKey! which_key_map.h<CR>
nnoremap <silent> <c-x>h :WhichKey! which_key_map.h<CR>
"""" 跳转再优化
" 把下一个查找匹配项所在的行显示在屏幕的最中间
nnoremap <silent> n nzz
nnoremap <silent> N Nzz
nnoremap <silent> * *zz
nnoremap <silent> # #zz
nnoremap <silent> g* g*zz
" 代码跳转后居中 + 多选择跳转:nmap <c-]> g<c-]>
nnoremap <silent> <c-]> g<c-]>zz
nnoremap <silent> <c-o> g<c-o>zz
nnoremap <silent> <c-i> g<c-i>zz
" 执行删除<silent> 操作时插入断点 Ctrl-G u (类似commit的操作)
" inoremap <silent> <silent> <c-u> <c-g>u<c-u>
" inoremap <silent> <c-w> <c-g>u<c-w>
" inoremap <silent> , ,<c-g>u
" inoremap <silent> . .<c-g>u
" inoremap <silent> / /<c-g>u
" inoremap <silent> \ \<c-g>u
" inoremap <silent> ; ;<c-g>u
" inoremap <silent> : :<c-g>u
" inoremap <silent> ' '<c-g>u
" inoremap <silent> " "<c-g>u
" inoremap <silent> [ [<c-g>u
" inoremap <silent> ] ]<c-g>u
" inoremap <silent> { {<c-g>u
" inoremap <silent> } }<c-g>u
" 开启折行显示选项时,按屏幕行移动
" \j 与下行连接
nnoremap <silent> \j @="Jj"<CR>
nnoremap <silent> <expr> \j "Jj"
nnoremap <silent> j gj
nnoremap <silent> k gk
" Makes gj/gk move by virtual lines when used without a count, and by physical lines when used with a count.
" nnoremap <silent> <expr> j (v:count == 0 ? 'gj' : 'j')
" nnoremap <silent> <expr> k (v:count == 0 ? 'gk' : 'k')
"""" 命令转快捷键
" 将命令行命令:q :w映射成\q \w
" Quit
inoremap <C-Q> <esc>:q<cr>
nnoremap <C-Q> :q<cr>
vnoremap <C-Q> <esc>
nnoremap <Leader>q :q<cr>
nnoremap <Leader>Q :qa!<cr>
" Save
inoremap <C-s> <C-O>:update<cr>
nnoremap <C-s> :update<cr>
nnoremap <leader>s :update<cr>
nnoremap <leader>w :update<cr>
nnoremap <leader>w :w<CR> " \w == :w
nnoremap <leader>m m, " \m == m,
" Repeat last substitution, including flags, with &.
nnoremap & :&&<CR>
xnoremap & :&&<CR>
" 编辑copy paste
nnoremap <leader>sa ggVG" " select All
vnoremap < <gv " > 用于增加缩进
vnoremap > >gv " < 用于减少缩进
vnoremap <leader>y "+ | " Linux粘贴板
" vnoremap <leader>y "* | " Windows粘贴板
nnoremap <leader>v "+p | " Linux粘贴板 粘贴
inoremap <leader>v <esc>"+p | " Linux粘贴板 粘贴
vnoremap <leader>v "+p | " Linux粘贴板 粘贴
nnoremap <leader>c "+y | " Linux粘贴板 复制
vnoremap <leader>c "+y | " Linux粘贴板 复制
""" Some shortcuts for system clipboards
noremap <leader>d "+d
noremap <leader>D "*d
noremap <leader>p "+p
noremap <leader>P "*p
noremap <leader>y "+y
noremap <leader>Y "*y
"" END editing keybindings
" Yank from the cursor to the end of the line, to be consistent with C and D.
nnoremap Y y$
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" remove space; remove ^M; remove tab; remove all; \sh shell file type
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" \rs 一键去除全部尾部空白
imap <leader>rs <esc>:let _s=@/<bar>:%s/\s\+$//e<bar>:let @/=_s<bar>:nohl<cr>
nmap <leader>rs :let _s=@/<bar>:%s/\s\+$//e<bar>:let @/=_s<bar>:nohl<cr>
vmap <leader>rs <esc>:let _s=@/<bar>:%s/\s\+$//e<bar>:let @/=_s<bar>:nohl<cr>
" \rm 一键去除全部 ^M 字符
imap <leader>rm <esc>:%s/<c-v><c-m>//g<cr>
nmap <leader>rm :%s/<c-v><c-m>//g<cr>
vmap <leader>rm <esc>:%s/<c-v><c-m>//g<cr>
" \rt 一键替换全部 Tab 为空格
nmap <leader>rt <esc>:retab<cr>
" \ra 一键清理当前代码文件
nmap <leader>ra <esc>\rt<esc>\rs<esc>gg=G<esc>gg<esc>
" \sh
nmap <leader>sh <esc>:set ft=sh<CR>
nnoremap <silent> <c-x><c-r> :WhichKey! which_key_map.r<CR>
nnoremap <silent> <c-x>r :WhichKey! which_key_map.r<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" vim tab buffer simulate tmux windows manager; windows simulate pane
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""" tab
nnoremap <silent> <C-s>c :tabnew<cr>
nnoremap <silent> <C-s>b :tab ba<cr>
nnoremap <silent> <C-s>x :tabclose<cr>
nnoremap <silent> <C-s>s :tabs<cr>
nnoremap <silent> <C-s>0 :tabfirst<cr>
nnoremap <silent> <C-s>w <C-w>t<cr>
nnoremap <silent> <C-s><C-c> :tabnew<cr>
nnoremap <silent> <C-s><C-x> :tabclose<cr>
nnoremap <silent> <C-s><C-s> :tabs<cr>
nnoremap <silent> <C-s><C-0> :tabfirst<cr>
nnoremap <silent> <C-s>n gt
nnoremap <silent> <C-s>p gT
nnoremap <silent> <C-s><C-n> gt
nnoremap <silent> <C-s><C-p> gT
nnoremap <silent> <C-s>f :tabfirst<cr>
nnoremap <silent> <C-s>l :tablast<cr>
nnoremap <silent> <C-s><C-f> :tabfirst<cr>
nnoremap <silent> <C-s><C-l> :tablast<cr>
nnoremap <silent> <C-s>1 1gt
nnoremap <silent> <C-s>2 2gt
nnoremap <silent> <C-s>3 3gt
nnoremap <silent> <C-s>4 4gt
nnoremap <silent> <C-s>5 5gt
nnoremap <silent> <C-s>6 6gt
nnoremap <silent> <C-s>7 7gt
nnoremap <silent> <C-s>8 8gt
nnoremap <silent> <C-s>9 9gt
nnoremap <silent> <c-x><c-s> :WhichKey! which_key_map.s<CR>
nnoremap <silent> <c-x>s :WhichKey! which_key_map.s<CR>
nnoremap <silent> <leader>n <down>
nnoremap <silent> <leader>p <up>
nnoremap <silent> <leader>1 1gt
nnoremap <silent> <leader>2 2gt
nnoremap <silent> <leader>3 3gt
nnoremap <silent> <leader>4 4gt
nnoremap <silent> <leader>5 5gt
nnoremap <silent> <leader>6 6gt
nnoremap <silent> <leader>7 7gt
nnoremap <silent> <leader>8 8gt
nnoremap <silent> <leader>9 9gt
nnoremap <silent> <leader>0 :tabs<cr>
let g:which_key_map.1 = 'which_key_ignore'
let g:which_key_map.2 = 'which_key_ignore'
let g:which_key_map.3 = 'which_key_ignore'
let g:which_key_map.4 = 'which_key_ignore'
let g:which_key_map.5 = 'which_key_ignore'
let g:which_key_map.6 = 'which_key_ignore'
let g:which_key_map.7 = 'which_key_ignore'
let g:which_key_map.8 = 'which_key_ignore'
let g:which_key_map.9 = 'which_key_ignore'
let g:which_key_map.0 = 'which_key_ignore'
"""" buffer(args) b conflict with tmux, use screen hotkey a
nnoremap <silent> <C-a>a :ls<CR>
nnoremap <silent> <C-a>b :tab ba<CR>
nnoremap <silent> <C-a>0 :bfirst<CR>
nnoremap <silent> <C-a>c :new<CR>
nnoremap <silent> <C-a>x :bdelete<CR>
nnoremap <silent> <C-a><C-a> :ls<CR>
nnoremap <silent> <C-a><C-0> :bfirst<CR>
nnoremap <silent> <C-a><C-c> :new<CR>
nnoremap <silent> <C-a><C-x> :bdelete<CR>
nnoremap <silent> <C-a>n :bnext<CR>
nnoremap <silent> <C-a>p :bprev<CR>
nnoremap <silent> <C-a><C-n> :bnext<CR>
nnoremap <silent> <C-a><C-p> :bprev<CR>
nnoremap <silent> <C-a>f :bfirst<cr>
nnoremap <silent> <C-a>l :blast<cr>
nnoremap <silent> <C-a><C-f> :bfirst<cr>
nnoremap <silent> <C-a><C-l> :blast<cr>
"c-^ e#
nnoremap <silent> <C-a>1 :b1<cr> " e#1
nnoremap <silent> <C-a>2 :b2<cr> " e#2
nnoremap <silent> <C-a>3 :b3<cr> " e#3
nnoremap <silent> <C-a>4 :b4<cr> " e#4
nnoremap <silent> <C-a>5 :b5<cr> " e#5
nnoremap <silent> <C-a>6 :b6<cr> " e#6
nnoremap <silent> <C-a>7 :b7<cr> " e#7
nnoremap <silent> <C-a>8 :b8<cr> " e#8
nnoremap <silent> <C-a>9 :b9<cr> " e#9
nnoremap <silent> <c-x><c-a> :WhichKey! which_key_map.a<CR>
nnoremap <silent> <c-x>a :WhichKey! which_key_map.a<CR>
nnoremap <silent> <c-x><c-b> :WhichKey! which_key_map.b<CR>
nnoremap <silent> <c-x>b :WhichKey! which_key_map.b<CR>
"""" reload buffer
nnoremap <C-a>u :e!<CR>redraw<CR>
nnoremap <C-a>U :bufdo :e!<CR>redraw<CR>
"""" windows
" tmux % == CTRL-W_s
" tmux " == CTRL-W_v
" tmux x == CTRL-W_c
nnoremap <silent> <C-w>z <C-w>|
nnoremap <silent> <C-w><C-z> <C-w>|
nnoremap <silent> <C-w>Z <C-w>_
" shortcuts for opening new split windows
nnoremap <silent> <leader>h :split<CR><C-w><C-w>
nnoremap <silent> <leader>v :vsplit<CR><C-w><C-w>
nnoremap <silent> <leader>q :q<CR>
nnoremap <silent> <leader>Q :q!<CR>
nnoremap <silent> <c-x><c-w> :WhichKey! which_key_map.w<CR>
nnoremap <silent> <c-x>w :WhichKey! which_key_map.w<CR>
"""" QuickFix
nnoremap <silent> <C-c>c :copen<CR>
nnoremap <silent> <C-c>x :cclose<CR>
nnoremap <silent> <C-c>p :cnext<CR>
nnoremap <silent> <C-c>n :cprevious<CR>
nnoremap <silent> <C-c>f :cfirst<CR>
nnoremap <silent> <C-c>l :clast<CR>
nnoremap <silent> <C-c><C-c> :copen<CR>
nnoremap <silent> <C-c><C-x> :cclose<CR>
nnoremap <silent> <C-c><C-p> :cnext<CR>
nnoremap <silent> <C-c><C-n> :cprevious<CR>
nnoremap <silent> <C-c><C-f> :cfirst<CR>
nnoremap <silent> <C-c><C-l> :clast<CR>
nnoremap <silent> <c-x><c-c> :WhichKey! which_key_map.c<CR>
nnoremap <silent> <c-x>c :WhichKey! which_key_map.c<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" misc session buffertotab termianl and AutoTag
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""" session
nnoremap <C-a>s :wall<CR>:mksession! ./.session.vim<CR>
nnoremap <C-a>r :source ./.session.vim<CR>
nnoremap <C-a><C-s> :wall<CR>:mksession! ./.session.vim<CR>
nnoremap <C-a><C-r> :source ./.session.vim<CR>
set sessionoptions=buffers " Save hidden, unloaded buffers in session
set ssop+=help " Save the help window(s)
set ssop+=localoptions " Keep any local options or mappings
set ssop+=resize " Size of the Window: 'lines' and 'columns'
set ssop+=slash " Replace back with fack in session file
set ssop+=tabpages " Store all tabs in session
set ssop+=unix " Use Unix line endings for session file
set ssop+=winpos " Position of the Vim Window
set ssop+=winsize " Size of each window
"""" 把buffer中的文件全转成tab # :bufdo tab split 或者 :tab sball
nnoremap <C-a>t :bufdo tab split<CR>
nnoremap <C-a><c-t> :bufdo tab split<CR>
"""" Terminal
nnoremap <C-a>T :vert terminal<CR>
"""" Tag
nnoremap <C-a>P :!touch ./.project<CR>
nnoremap <silent> <c-x><c-x> :WhichKey! which_key_map.x<CR>
nnoremap <silent> <c-x>x :WhichKey! which_key_map.x<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" vim mark simulate tmux windows manager
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""" vim-bookmarks
nnoremap <C-m>t :BookmarkToggle<CR>
nnoremap <C-m>a :BookmarkAnnotate<CR>
nnoremap <C-m>m :BookmarkShowAll<CR>
nnoremap <C-m>n :BookmarkNext<CR>
nnoremap <C-m>p :BookmarkPrev<CR>
nnoremap <C-m>x :BookmarkClear<CR>
nnoremap <C-m>c :BookmarkClearAll<CR>
nnoremap <C-m>u :BookmarkMoveUp<CR>
nnoremap <C-m>d :BookmarkMoveDown<CR>
nnoremap <C-m>l :BookmarkMoveToLine<CR>
nnoremap <C-m>s :BookmarkSave ./.bookmark<CR>
nnoremap <C-m>r :BookmarkLoad ./.bookmark<CR>
nnoremap <C-m><C-t> :BookmarkToggle<CR>
nnoremap <C-m><C-a> :BookmarkAnnotate<CR>
nnoremap <C-m><C-m> :BookmarkShowAll<CR>
nnoremap <C-m><C-n> :BookmarkNext<CR>
nnoremap <C-m><C-p> :BookmarkPrev<CR>
nnoremap <C-m><C-x> :BookmarkClear<CR>
nnoremap <C-m><C-c> :BookmarkClearAll<CR>
nnoremap <C-m><C-u> :BookmarkMoveUp<CR>
nnoremap <C-m><C-d> :BookmarkMoveDown<CR>
nnoremap <C-m><C-l> :BookmarkMoveToLine<CR>
nnoremap <C-m><C-s> :BookmarkSave ./.bookmark<CR>
nnoremap <C-m><C-r> :BookmarkLoad ./.bookmark<CR>
nnoremap <silent> <c-x><c-m> :WhichKey! which_key_map.m<CR>
nnoremap <silent> <c-x>m :WhichKey! which_key_map.m<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" cnoremap and inoremap simulate readline
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" cnoremap
" Ctrl + p 和 Ctrl + n 来跳转到上一个/下一个条目
cnoremap <c-n> <down>
cnoremap <c-p> <up>
cnoremap <c-a> <Home>
cnoremap <c-e> <End>
cnoremap <c-b> <Left>
cnoremap <c-f> <Right>
cnoremap <c-d> <Del>
" %% for current buffer file name
" :: for current buffer file path
cnoremap %% <c-r>=expand('%')<cr>
cnoremap :: <c-r>=expand('%:p:h')<cr>/
cnoremap w!! w !sudo tee >/dev/null % " w! save changes even if file is read-only, provided user has appropriate permissions
" inoremap
inoremap <c-a> <home>
inoremap <c-e> <end>
inoremap <c-b> <left>
inoremap <c-f> <right>
inoremap <c-z> <Esc>zza
" Insert mode navigation similar to <C-g>j and <C-g>k
inoremap <silent> <C-g>l <right>
inoremap <silent> <C-g>h <left>
inoremap <silent> <C-g><C-l> <right>
inoremap <silent> <C-g><C-h> <left>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" vimrc macros
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" /usr/share/vim/vim81/pack/dist/opt/matchit/autoload
packadd! matchit " 扩展了%命令的功能,支持if/else/endif语法结构;支持HTML标签.
set clipboard+=unnamed " 与windows共享剪切板
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" vimrc
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if has('autocmd')
" Remove ALL autocommands for the current group
au!
endif
let mapleader="\\"
let localleader="\\"
nnoremap s% :source %<cr> " vim script source
nnoremap r% :read! %<cr> " vim script reload
" vimrc defaults file
source $VIMRUNTIME/defaults.vim
" Fast reloading of the .vimrc
nnoremap ss :source $MYVIMRC<cr>
" Fast editing of .vimrc
nnoremap ee :tabe $MYVIMRC<cr>
" When .vimrc is edited, reload it
nnoremap rr :e %<cr>
" autocmd BufWritePost $MYVIMRC source $MYVIMRC
augroup enableAutoReloadVimrc
autocmd!
autocmd BufWritePost *vimrc source ${MYVIMRC} | set foldmethod=marker
autocmd BufWritePost *gvimrc if has('gui_running') source source ${MYVIMRC}
augroup END
augroup enableAutoSaveSession
autocmd!
" autocmd VimLeave * mksession! ./session.vim
" autocmd VimEnter * source ./session.vim
augroup END
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 基本配置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 关闭兼容模式
set nocompatible " disable backwards-compatible with vi
set shortmess=atI " 关闭乌干达儿童提示
set diffopt=filler,vertical " Keep files aligned, default to vsplit
set splitright " Open vertical splits on the right
" 高亮显示匹配的括号
set showmatch " set show matching parenthesis
" set paste " 粘贴保持格式
" 启用鼠标
" set mouse=a
" set selection=exclusive
" set selectmode=mouse,key
" 设置编码utf-8
set fileencoding=utf-8
set encoding=utf-8
set tenc=utf-8
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
language message en_US.UTF-8
set helplang=cn
" term 与 t_Co 有的颜色主题可能还与终端与终端色数量有关
" 启用256色
set t_Co=256
" 颜色主题 是放在运行时各路径的 colors/ 子目录的 *.vim 文件
" colorscheme这是个单独的命令,不是 set 选项.选择一个颜色主题
" :colorscheme + 主题名 -> :colorscheme helloworld -> colors/helloworld.vim
colorscheme desert " darkblue
" background 背景是深色 dark 或浅色 light, 有的 colorscheme 只适于深色或 浅色背景,有的则分别为不同背景色定义不同的颜色主题
" set background=dark
set ttyfast " Faster redrawing.
set lazyredraw " Only redraw when necessary.
set splitbelow " Open new windows below the current window.
set splitright " Open new windows right of the current window.
set clipboard+=unnamed,unnamedplus " 复制到系统寄存器(*) 复制到系统寄存器(+)
set history=1000 " 最大历史记录 (default is 20)
" 开启语法高亮功能
syntax enable
" 允许用指定语法高亮配色方案替换默认方案 | " Enable syntax highlighting.
syntax on
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"设置行号 + 行号的列宽
set number
" set numberwidth=4
" set numberwidth?
" 突出显示当前行和当前列
" set cursorline
" set cursorcolumn
let g:indentLine_enabled = 1 " indentLine 开启代码对齐线
" 只想让这个效果出现在当前窗口,而且在插入模式中关闭这个效果
autocmd InsertLeave,WinEnter * set cursorline
autocmd InsertEnter,WinLeave * set nocursorline
" 关闭自动折行
set nowrap
set whichwrap-=<,>,h,l " 设置光标键不跨行
"set whichwrap=b,s,h,l,<,>,~,[,] " everything wraps
" | | | | | | | | |
" | | | | | | | | +-- "]" Insert and Replace
" | | | | | | | +-- "[" Insert and Replace
" | | | | | | +-- "~" Normal
" | | | | | +-- <Right> Normal and Visual
" | | | | +-- <Left> Normal and Visual
" | | | +-- "l" Normal and Visual (not recommended)
" | | +-- "h" Normal and Visual (not recommended)
" | +-- <Space> Normal and Visual
" +-- <BS> Normal and Visual
set virtualedit-=block,onemore " 不允许光标出现在最后一个字符的后面
set wrapscan " Searches wrap around end-of-file.
set report =0 " Always report changed lines.
set synmaxcol =200 " Only highlight the first 200 columns.
set shortmess-=S " display number of search matches & index of a current match
" 插入模式下在哪里允许 <BS> 删除光标前面的字符.逗号分隔的三个值分别指:行首的空白字符,换行符和插入模式开始处之前的字符。
set backspace=indent,eol,start " allow backspacing over everything in insert mode
set confirm " Show confirm dialog
set hidden " Switch between buffers without having to save first
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 显示状态栏
set laststatus=2
" 底部显示
" 在底部显示当前模式
set showmode " Show current mode in command-line.
" 在底部显示当前指令
set showcmd " Show already typed keys when more are expected.
" 在状态栏中显示光标所在位置
set ruler
" |-- VISUAL -- 2f 43,8 17% |
" +-------------------------------------------------+
" ^^^^^^^^^^^ ^^^^^^^^ ^^^^^^^^^^
" 'showmode' 'showcmd' 'ruler'
" 状态行显示的内容
" 自定义状态行
set statusline=%1*\%<%.50F\ " 显示当前文件相对路径
set statusline+=%=%2*\%y%m%r%h%w\ " 显示文件类型和文件状态
set statusline+=%3*\%{&ff}\[%{&fenc}]\ " 显示文件编码类型
set statusline+=%4*\ row:%l/%L,col:%c\ " 显示光标所在行与列
set statusline+=%5*\%3p%%\ " 显示当前光标位置百分比
" :highlight 可以查看高亮显示组的颜色定义
hi User1 cterm=none ctermfg=25 ctermbg=0
hi User2 cterm=bold ctermfg=1 ctermbg=0
hi User3 cterm=bold ctermfg=1 ctermbg=0
hi User4 cterm=bold ctermfg=6 ctermbg=0
hi User5 cterm=bold ctermfg=green ctermbg=0
" 总是显示状态行
set laststatus=2 " Always show statusline.
set display=lastline " Show as much as possible of the last line.
" vim命令自动补全: 状态行上显示补全匹配, 按了 <Tab> 后有多于一个匹配的情况
set wildmenu " turn on command line completion wild style
set wildmode=longest:list,full
set wildignore=*.dll,*.exe,*.gif,*.jpg,*.mm ",*.png,*.snag,*.ssd,*.xmind " 影响 expand() globpath()和glob()的结果,这些函数被很多插件用来在系统中执行查找
set wildignore+=*/.git/*,*/.hg/*,*/.svn/* " Linux/MacOSX
" set wildignore+=*\\.git\\*,*\\.hg\\*,*\\.svn\\* " Windows ('noshellslash')
set esckeys " Allow cursor keys in insert mode
set modeline " Respect modeline in files
set modelines=4
" 按 Esc 的生效更快速.通常 Vim 要等待一秒来看看 Esc 是否是转义序列的开始.如果你使用很慢的远程连接,增加此数值
" set timeout
" set timeoutlen=100
" 如果末行被截短,显示 @@@ 而不是隐藏整行
set display=truncate
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 空格和tab键
set nolist
set listchars=tab:>-,trail:-
if has('multi_byte') && &encoding ==# 'utf-8'
let &listchars = 'tab:▸ ,extends:❯,precedes:❮,nbsp:±'
else
let &listchars = 'tab:> ,extends:>,precedes:<,nbsp:.'
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"禁用错误报警声音和图标
set noerrorbells
set novisualbell
set t_vb=
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"禁止生成临时文件
set nobackup
set noswapfile
" Put all temporary files under the same directory.
" https://github.com/mhinz/vim-galore#handling-backup-swap-undo-and-viminfo-files
" 如果文件夹不存在,则新建文件夹
if !isdirectory($HOME.'/.vim/files') && exists('*mkdir')
call mkdir($HOME.'/.vim/files')
endif
" 备份文件
set backup " make backup files
set backupdir =$HOME/.vim/files/backup/ " where to put backup files
set backupext =-vimbackup "
set backupskip =$HOME/.vim/files/backup/ " Don’t create backups when editing files in certain directories
" 交换文件
set directory =$HOME/.vim/files/swap/
set updatecount =100
" 撤销文件
set undofile
set undodir =$HOME/.vim/files/undo/
set undolevels =1000 " use many muchos levels of undo
" viminfo 文件
set viminfo ='100,n$HOME/.vim/files/info/viminfo
set viminfo=<100,'100,/50,:100,h,r$TEMP:,s10
" | | | | | | + 不保存超过10KB寄存器
" | | | | | + 不保存TEMP目录下文件的相关信息
" | | | | + 载入viminfo文件时关闭hlsearch高亮
" | | | + 保存命令历史条数
" | | + 保存搜索历史条数
" | + 保存最近100个文件中的标记
" + 每个寄存器中保存的行数
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 格式控制
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""" 自动探测
" 开启文件类型侦测
filetype on
" 根据侦测到的不同类型加载对应的插件
filetype plugin on
" 文件类型检查,自适应不同语言的智能缩进
filetype indent on
filetype plugin indent on " Load plugins according to detected filetype.
"文件自动检测外部更改
set autoread
set autowrite
"formatoptions(TODO) 控制自动格式化文本的许多选项
"""" 手动设置
"textwidth(TODO) 文本行宽度,超过该宽度(默认78)时自动加回车换回
" 按下回车键后,下一行的缩进会自动跟上一行的缩进保持一致(插入模式下回车自动缩进)
set autoindent " Indent according to previous line
set copyindent " copy the previous indentation on autoindenting
set smartindent
" 将制表符扩展为空格
set expandtab " Use spaces instead of tabs
"" make/cmake
augroup vimrc-make-cmake
autocmd!
autocmd FileType make setlocal noexpandtab
autocmd BufNewFile,BufRead CMakeLists.txt setlocal filetype=cmake
augroup END
" 设置格式化时制表符占用空格数
set shiftwidth=4 " >> indents by 4 spaces.
set shiftround " >> indents to next multiple of 'shiftwidth'.
" 设置编辑时制表符占用空格数
set tabstop=4 " 硬制表符宽度
" 让 vim 把连续数量的空格视为一个制表符
set softtabstop=4 " Tab key indents by 4 spaces.
set smarttab " insert tabs on the start of a line according to shiftwidth, not tabstop
"c文件自动缩进
set cindent
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 拼写
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"拼写检查
set nospell
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 搜索
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 高亮搜索结果
set hlsearch " Keep matches highlighted.
" nnoremap <Esc> :nohlsearch<CR> # 影响<UP><DOWN>键
" inoremap <Esc> <Esc>:nohlsearch<CR> # 影响<UP><DOWN>键
" nnoremap <esc><esc> :nohl<CR>
" no highlight after search
" noremap <C-n> :nohl<CR>
" vnoremap <C-n> :nohl<CR>
" inoremap <C-n> :nohl<CR>
" 自动跳转到第一个匹配的结果
set incsearch " show search matches as you type
" 搜索时只小写字母忽略大小写,有大写字母则大小写敏感
set ignorecase " ignore case when searching
set infercase " ignore case when auto-complete
set smartcase " ignore case if search pattern is all lowercase, case-sensitive otherwise
set ignorecase smartcase " 搜索词全部是小写时,进行大小写不敏感搜索;当搜索词 至少有1个大写字母时,进行大小写敏感搜索
" n 始终为向后搜索,N 始终为向前搜索
nnoremap <expr> n 'Nn'[v:searchforward]
nnoremap <expr> N 'nN'[v:searchforward]
""""""""""""""""""""""""""""""""""""""""
" 折叠 za:打开或关闭当前折叠/zM:关闭所有折叠/zR:打开所有折叠
""""""""""""""""""""""""""""""""""""""""
set nofoldenable "启动 vim 时关闭折叠代码
" set foldenable "允许折叠
set fdm=syntax "基于语法进行代码折叠
set fdm=manual "手动折叠
set foldmethod=indent "基于缩进进行代码折叠
set foldlevel=99
" 用空格键来切换折叠,即相当于命令 za,但如果当前行根本就没有折叠,那就无所谓切换折叠了,那就换用命令 } 跳到下一个空行
nnoremap <Space> @=(foldlevel(line('.'))>0) ? "za" : "}"<CR>
nnoremap <expr> <Space> (foldlevel(line('.'))>0) ? "za" : "}"
function! ToggleFold()
if foldlevel(line('.')) > 0
return "za"
else
return "}"
endif
endfunction
nnoremap <expr> <Space> ToggleFold()
nnoremap <leader>f0 :set foldlevel=0<CR>
nnoremap <leader>f1 :set foldlevel=1<CR>
nnoremap <leader>f2 :set foldlevel=2<CR>
nnoremap <leader>f3 :set foldlevel=3<CR>
nnoremap <leader>f4 :set foldlevel=4<CR>
nnoremap <leader>f5 :set foldlevel=5<CR>
nnoremap <leader>f6 :set foldlevel=6<CR>
nnoremap <leader>f7 :set foldlevel=7<CR>
nnoremap <leader>f8 :set foldlevel=8<CR>
nnoremap <leader>f9 :set foldlevel=9<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" .vim/autoload/plug.vim 自动载入脚本 PlugInstall/PlugUpdate/PlugClean/PlugUpgrade/
" :help packages
" https://github.com/shiqf/dotfiles TODO Read
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Install vim-plug if it isn't already
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
" mkdir -p ~/.vim/pack/plugins/start 创建一个存储插件的目录
packloadall "加载所有插件
silent! helptags ALL "为所有插件加载帮助文档
" https://zhuanlan.zhihu.com/p/58816187 插件说明 vim-rainbow 插件
" https://github.com/yyq123/learn-vim 帮助文档
call plug#begin('~/.vim/plugged')
Plug 'vim-scripts/vim-addon-mw-utils' " 代码片段提示/函数库
Plug 'tomtom/tlib_vim' " 代码片段提示/函数库
Plug 'SirVer/ultisnips' " 代码片段提示/替换引擎
Plug 'honza/vim-snippets' " 代码片段提示/各种各样的snippets
" Plug 'Valloric/YouCompleteMe' " 代码补全 sudo apt-get install build-essential cmake python-dev python3-dev; ./install.py --clang-completer
" YCM 的高性能 + coc.nvim 的富交互 + vim-lsp 的 API 设计 = EasyComplete 的极简和纯粹
Plug 'jayli/vim-easycomplete' " 余杭区最好用的vim补全插件(vim 8.2及以上,nvim 0.4.4 及以上版本) :EasyCompleteGotoDefinition :EasyCompleteCheck :EasyCompleteInstallServer ${Plugin_Name} set dictionary=${Your_Dictionary_File}
Plug 'skywind3000/vim-dict' " VIM 词表收集
Plug 'mattn/webapi-vim' " Gist 代码段 API
Plug 'mattn/vim-gist' " Gist 代码段 命令
Plug 'bronson/vim-trailing-whitespace' " 去除文档多余的空白符 ws
Plug 'vim-autoformat/vim-autoformat' " 代码格式化
Plug 'rhysd/vim-clang-format' " apt install clang-format;
Plug 'tpope/vim-surround'
Plug 'tpope/vim-commentary' " 注释 gcc {count}gc gcap
Plug 'tpope/vim-unimpaired' " ]b和[b循环遍历缓冲区; ]f和[f循环遍历同一目录中的文件,并打开为当前缓冲区; ]l和[l遍历位置列表; ]q和[q遍历快速修复列表; ]t和[t遍历标签列表; yos切换拼写检查,或yoc切换光标行高亮显示
Plug 'vim-scripts/DoxygenToolkit.vim', {'for': ['c', 'cpp']} " 注释 DoxAuthor Dox DoxBlock DoxAll
Plug 'junegunn/vim-peekaboo' " \" Ctrl+R 显示寄存器内容
Plug 'Yilin-Yang/vim-markbar' " '` 显示mark的内容
Plug 'kshenoy/vim-signature' " mark 记录标注; m[a-zA-Z]:打标签,打两次就撤除/ m,:自动设定下一个可用书签名; mda:删除当前文件中所有独立书签
Plug 'MattesGroeger/vim-bookmarks' " bookmarks Ctrl-M
Plug 'vim-scripts/taglist.vim' " 浏览tags,文件内跳转 Tlist set tags=tags;
Plug 'preservim/tagbar' " 浏览tags,文件内跳转 Tagbar set tags=tags;
Plug 'skywind3000/vim-preview' " 预览tags中的函数 F11
Plug 'vim-scripts/a.vim' " 源文件/头文件之间跳转 :A :AS :AV :AN
" netrw Ex/Sex/Vex/Lex 左右分割方式,当前Netrw窗口位于最左边,且高度占满整个屏幕 :Ex sftp://<domain>/<directory> 列出目录内容, :e scp://<domain>/<directory>/<file> 编辑文件
Plug 'vim-scripts/winmanager' " 文件系统管理 WMToggle/wm
Plug 'jlanzarotta/bufexplorer' " opened buffer管理 \bs \bv \bt \be
Plug 'preservim/nerdtree' " directory管理 NERDTreeToggle/tree; :Bookmark命令来收藏当前光标在NERDTree中选择的目录; B列出所以书签
" Plug 'bagrat/vim-buffet' " buffer管理
Plug 'kien/ctrlp.vim' " find模糊搜索 <Ctrl>+p :CtrlP 或 :CtrlP {path} 或 :CtrlPBuffer 或 :CtrlPMRU 或 :CtrlPMixed
" <Leader>vv 搜索光标所在单词,并匹配出所有结果 <Leader>vV 搜索光标所在单词,全词匹配
" <Leader>va vv结果添加到之前的搜索列表 <Leader>vA vV把结果添加到之前的搜索列表
" <Leader>vr 全局搜索光标所在单词,并替换想要的单词
" :Grep [arg] # 类似 <Leader>vv, 使用 ! 类似<Leader>vV
" :GrepAdd [arg] # 类似 <Leader>va, 使用 ! 类似<Leader>vA
" :Replace [target] [replacement] # 类似 <Leader>vr
" :ReplaceUndo # 撤销替换操作
Plug 'dkprice/vim-easygrep' " grep模糊查找
" Plug 'junegunn/fzf.vim' " 模糊搜索
Plug 'jiangmiao/auto-pairs' " 括号自动补全
Plug 'vim-airline/vim-airline' " 状态栏
Plug 'vim-airline/vim-airline-themes' " 状态栏主题
Plug 'asins/vimcdoc' " vim中文文档 help
Plug 'vim-utils/vim-man' " vim Man Vman帮助文档
Plug 'vim-scripts/CRefVim' " c reference manual; \cr
Plug 'nanotee/nvim-lua-guide' " lua reference manual, :help lua.table
Plug 'hotchpotch/perldoc-vim' " apt-get install perl-doc; K hotkey
Plug 'bfrg/vim-cmake-help' " :CMakeHelp {arg} / :CMakeHelpPopup {arg} / :CMakeHelpOnline [{arg}]
" markdown + firefox
" Plug 'iamcco/mathjax-support-for-mkdp' " 实时通过浏览器预览 markdown 文件
" Plug 'iamcco/markdown-preview.vim' " 实时通过浏览器预览 markdown 文件 MarkdownPreview MarkdownPreviewStop
" Plug 'Yggdroot/LeaderF', { 'do': ':LeaderfInstallCExtension' }
" Plug 'skywind3000/vim-quickui'
Plug 'vim-syntastic/syntastic' " ALE 异步语法检查引擎
" Plug 'yegappan/mru' " Most Recently opened/edited files
" Plug 'yegappan/bufselect' " access to jump to a buffer from the Vim buffer list
" Plug 'yegappan/borland' " Classic borland IDE like Vim color scheme
" Plug 'mbbill/undotree' " 可视化管理内容变更历史记录的插件
Plug 'simnalamburt/vim-mundo' " 可视化管理内容变更历史记录的插件 :MundoToggle -> Gundo
" Plug 'Konfekt/FastFold' " 让 Vim 按需更新折叠内容,而不是一直调用
Plug 'vim-scripts/a.vim' " swtich between source files and header files
" Plug 'octol/vim-cpp-enhanced-highlight' " c++ syntax highlighting
" Plug 'xavierd/clang_complete' " uses clang for accurately completing C and C++ code
Plug 'liuchengxu/vim-which-key' " c-xc-x hotkey help
Plug 'tpope/vim-fugitive'
Plug 'iberianpig/tig-explorer.vim'
" Plug 'xolox/vim-lua-ftplugin' " Lua file type
" Plug 'tbastos/vim-lua', {'for': 'lua'} " lua的高亮和缩进
" Plug 'xolox/vim-lua-inspect' " uses the [LuaInspect] lua-inspect tool to (automatically) perform semantic highlighting of variables in Lua source code
" Plug 'christoomey/vim-tmux-navigator' "
call plug#end()
let g:which_key_map['p'] = {
\ 'name' : '+plugin' ,
\ 'S': ['PlugSnapshot', 'snapshot'],
\ 'U': ['PlugUpgrade', 'upgrade'],
\ 'c': ['PlugClean', 'clean'],
\ 'd': ['PlugDiff', 'diff'],
\ 'i': ['PlugInstall', 'install'],
\ 's': ['PlugStatus', 'status'],
\ 'u': ['PlugUpdate', 'update'],
\ }
nnoremap <silent> <c-x><c-p> :WhichKey! which_key_map.p<CR>
nnoremap <silent> <c-x>p :WhichKey! which_key_map.p<CR>
" neocompletecache -> neocomplete -> deoplete/neocompletion-manager(下一代通用补全)
" CtrlP / CommandT -> Unite.vim + vimproc -> denite.vim
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 'SirVer/ultisnips' + 'honza/vim-snippets'
" <c-j>展开 <c-tab>列出snippets <c-j>跳到下一个位置 <c-k>跳到上一个位置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" - https://github.com/Valloric/YouCompleteMe
" - https://github.com/nvim-lua/completion-nvim
let g:UltiSnipsExpandTrigger="<tab>"
" 使用 <c-b> 切换下一个触发点, <c-z>上一个触发点
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"