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
|
set nocompatible
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
noremap <F2> :Autoformat<CR>
nnoremap <silent><F3> :call <SID>ToggleColorColumn()<cr> " Show Column
nmap <F4> :ALEDetail<CR> " ALE detail info
nmap <silent><F5> :NERDTreeToggle<CR> " Nerd
nmap <silent><F8> :TagbarToggle<CR> " Tagbar
nnoremap <silent><F9> :call asyncrun#quickfix_toggle(5)<cr>" Show build window
" nnoremap <silent><F10> :AsyncRun -cwd=<root> cd `pwd`/build && bash ../kickstart.sh <cr>
nnoremap <silent><F10> :AsyncRun -cwd=<root> cd `pwd`/build && bash ../kickstart.sh && make install <cr>
map <F12> :%s/\t/ /g<CR>
" imap tt <Esc> " ff to exit insert mode
" 定义快捷键的前缀,即<Leader>
let mapleader=";"
let maplocalleader=";"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" Plug
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
call plug#begin()
" Code completion -------------------------------------------------------------
Plug 'neoclide/coc.nvim', {'branch': 'release'}
" Color Theme -----------------------------------------------------------------
Plug 'sainnhe/everforest'
Plug 'frazrepo/vim-rainbow'
Plug 'mechatroner/rainbow_csv'
let g:disable_rainbow_hover = 1
let g:rainbow_comment_prefix = '#'
" Status Bar ------------------------------------------------------------------
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
"" Adding extras.
"" Uncomment the following line If you have installed the powerline fonts.
"" It is good for airline layer.
let g:airline_powerline_fonts = 1
let g:airline_theme='everforest'
" AIRLINE SETTINGS
let g:airline#extensions#tabline#show_close_button = 0
"" AIRLINE SETTINGS
let g:airline#extensions#tabline#show_close_button = 0
" let g:airline#extensions#tabline#buffer_nr_show = 1 " 不要显示 index
let g:airline#extensions#tabline#buffer_idx_mode = 1
nmap <leader>1 <Plug>AirlineSelectTab1
nmap <leader>2 <Plug>AirlineSelectTab2
nmap <leader>3 <Plug>AirlineSelectTab3
nmap <leader>4 <Plug>AirlineSelectTab4
nmap <leader>5 <Plug>AirlineSelectTab5
nmap <leader>6 <Plug>AirlineSelectTab6
nmap <leader>7 <Plug>AirlineSelectTab7
nmap <leader>8 <Plug>AirlineSelectTab8
nmap <leader>9 <Plug>AirlineSelectTab9
" let g:airline_skip_empty_sections = 1
let g:airline_skip_empty_sections = 1
let g:airline#extensions#tabline#fnamemod = ':t'
""let g:airline#extensions#syntastic#enabled = 0
let g:airline_detect_iminsert=1
let g:airline#extensions#tmuxline#enabled = 0
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#show_tabs = 1
let g:airline#extensions#tabline#show_buffers = 1
let g:airline#extensions#tabline#show_tab_nr = 0
let g:airline#extensions#tabline#tab_nr_type = 1 " tab number
let g:airline#extensions#tabline#show_splits = 0
let g:airline#extensions#wordcount#enabled = 0
"let g:airline_theme='base16'
" let g:airline_powerline_fonts = 1
let g:airline#extensions#tagbar#enabled = 1
" END AIRLINE SETTINGS
let g:airline#extensions#tabline#show_tabs = 0
" Nerd Tree--------------------------------------------------------------------
Plug 'scrooloose/nerdtree'
Plug 'preservim/nerdcommenter'
" nerdtree 从当前文件目录打开
autocmd BufEnter * lcd %:p:h
"如果想打开vim时自动打开NERDTree,可以如下设定
" autocmd vimenter * NERDTree
" 显示行号
let NERDTreeShowLineNumbers=1
let NERDTreeAutoCenter=1
" 是否显示隐藏文件
" 在终端启动vim时,共享NERDTree
let g:nerdtree_tabs_open_on_console_startup=1
" 忽略以下文件的显示
let NERDTreeIgnore=['\.pyc','\~$','\.swp']
" 显示书签列表
let NERDTreeShowBookmarks=1
"NERDTree配置
let NERDChristmasTree=1 "显示增强
let NERDTreeAutoCenter=1 "自动调整焦点
let NERDTreeShowFiles=1 "显示文件
let NERDTreeShowLineNumbers=1 "显示行号
let NERDTreeHightCursorline=1 "高亮当前文件
let NERDTreeShowHidden=1 "显示隐藏文件
let NERDTreeMinimalUI=0 "不显示'Bookmarks' label 'Press ? for help'
let NERDTreeWinSize=30 "窗口宽度
" let NERDTreeQuitOnOpen = 1
let NERDTreeMinimalUI = 1
let NERDTreeDirArrows = 1
set autochdir
let NERDTreeChDirMode=2
" File Icon -------------------------------------------------------------------
Plug 'ryanoasis/vim-devicons'
"Can be enabled or disabled
let g:webdevicons_enable_nerdtree = 1
"whether or not to show the nerdtree brackets around flags
let g:webdevicons_conceal_nerdtree_brackets = 1
"adding to vim-airline's tabline
let g:webdevicons_enable_airline_tabline = 1
"adding to vim-airline's statusline
let g:webdevicons_enable_airline_statusline = 1
" pair and indent -------------------------------------------------------------
Plug 'jiangmiao/auto-pairs'
Plug 'Yggdroot/hiPairs'
"auto pair --------------------------------------------------------------------
"设置要自动配对的符号
let g:AutoPairs={'(':')', '[':']', '{':'}',"'":"'",'"':'"', '`':'`'}
"let g:AutoPairs = {'(':')', '[':']', '{':'}',"'":"'",'"':'"'}
"添加要自动配对的符号 <>
"let g:AutoPairs['<']='>'
"把 BACKSPACE 键映射为删除括号对和引号,默认为 1。
let g:AutoPairsMapBS = 1
"当g:AutoPairsMapCR为 1 时,且文本位于窗口底部时,自动移到窗口中间
let g:AutoPairsCenterLine = 1
" au Filetype markdown let b:AutoPairs={'(':')', '[':']', '{':'}','"':'"', '`':'`'}
let g:AutoPairsFlyMode = 0
let g:AutoPairsShortcutBackInsert = '<M-b>'
"white space at end of line
let g:better_whitespace_enabled=1
let g:strip_whitespace_on_save=1
autocmd BufWritePre * :%s/\s\+$//e
let g:current_line_whitespace_disabled_soft=1
" if confirm
let g:strip_whitespace_confirm=0
"only modified line
let g:strip_only_modified_lines=1
" white list
" let g:better_whitespace_filetypes_blacklist=['<filetype1>', '<filetype2>', '<etc>']
nnoremap ]w :NextTrailingWhitespace<CR>
nnoremap [w :PrevTrailingWhitespace<CR>
" pair and indent -------------------------------------------------------------
Plug 'nathanaelkane/vim-indent-guides'
" Plug 'lukas-reineke/indent-blankline.nvim'
" surround --------------------------------------------------------------------
Plug 'tpope/vim-surround'
" git
Plug 'tpope/vim-fugitive'
" git blame
nnoremap gb :Git blame<CR><CR>
" git log
nnoremap gl :Git log %<CR><CR>
Plug 'airblade/vim-gitgutter'
function! GitStatus()
let [a,m,r] = GitGutterGetHunkSummary()
return printf('+%d ~%d -%d', a, m, r)
endfunction
set statusline+=%{GitStatus()}
let g:gitgutter_sign_added = '+'
let g:gitgutter_sign_modified = '^'
let g:gitgutter_sign_removed = '-'
let g:gitgutter_sign_modified_removed = '^-'
highlight GitGutterAdd ctermfg=blue
highlight GitGutterChange ctermfg=green
highlight GitGutterDelete ctermfg=red
Plug 'zivyangll/git-blame.vim'
nnoremap <Leader>gg :<C-u>call gitblame#echo()<CR>
" python3 ---------------------------------------------------------------------
Plug 'vim-python/python-syntax'
let g:python_highlight_all = 1
" interestingwords ------------------------------------------------------------
Plug 'lfv89/vim-interestingwords'
" cpp -------------------------------------------------------------------------
Plug 'octol/vim-cpp-enhanced-highlight', {'for':'cpp'}
Plug 'bfrg/vim-cpp-modern', {'for':'cpp'}
Plug 'derekwyatt/vim-fswitch', {'for':['cpp','hpp']}
Plug 'Konfekt/FastFold'
" highlight Cpp
let g:cpp_class_scope_highlight = 1
let g:cpp_member_variable_highlight = 1
let g:cpp_class_decl_highlight = 1
let g:cpp_posix_standard = 1
" let g:cpp_experimental_simple_template_highlight = 1
" let g:cpp_experimental_template_highlight = 1
let g:cpp_concepts_highlight = 1
let g:cpp_no_function_highlight = 0
" Disable function highlighting (affects both C and C++ files)
let g:cpp_no_function_highlight = 0
" Enable highlighting of C++11 attributes
let g:cpp_attributes_highlight = 1
" Highlight struct/class member variables (affects both C and C++ files)
let g:cpp_member_highlight = 1
" Put all standard C and C++ keywords under Vim's highlight group 'Statement'
" (affects both C and C++ files)
let g:cpp_simple_highlight = 1
" LeaderF
Plug 'Yggdroot/LeaderF', { 'do': ':LeaderfInstallCExtension' }
Plug 'skywind3000/Leaderf-snippet'
Plug 'ludovicchabant/vim-gutentags'
" Track the engine.
Plug 'SirVer/ultisnips'
" Snippets are separated from the engine. Add this if you want them:
Plug 'honza/vim-snippets'
" cursor
Plug 'mg979/vim-visual-multi', {'branch': 'master'}
" fzf
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'yuki-yano/fzf-preview.vim', { 'branch': 'release/rpc' }
" misc
Plug 'skywind3000/asyncrun.vim'
Plug 'skywind3000/vim-quickui'
" Plug 'powerline/powerline-fonts'
" REPL
Plug 'sillybun/vim-repl', { 'for': ['python', 'r'], 'on':'REPLToggle' }
call plug#end()
""<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set encoding=UTF-8
set fileencodings=ucs-bom,utf-8,chinese
set nocompatible " 去除VI一致性,必须要添加
set autoread
"filetype off " 必须要添加
" 让配置变更立即生效
autocmd BufWritePost $MYVIMRC source $MYVIMRC
autocmd! bufwritepost .vimrc source %
" Backups ---------------------------------------------------------------------
set nobackup " do not keep backups after close
set nowritebackup " do not keep a backup while working
set noswapfile " don't keep swp files either
set backupdir=~/.vim/backup " store backups under ~/.vim/backup
set backupcopy=yes " keep attributes of original file
set backupskip=/tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*
set directory=~/.vim/swap,~/tmp,. " keep swp files under ~/.vim/swap
" color theme -----------------------------------------------------------------
syntax on
colorscheme everforest
set background=dark " For dark-mode version.
" set background=light " For light-mode version.
" basic config
set backspace=indent,eol,start " better backspace
filetype plugin on " load filetype-specific plugin
filetype indent on " load filetype-specific indent files
set wildmenu " visual autocomplete for command menu
set lazyredraw " redraw only when we need to.
set softtabstop=4 " number of spaces in tab when editing
set shiftwidth=4 " 4 space
set tabstop=4 " tab as 4 space
set expandtab " tabs are spaces
" indent-guides settings ------------------------------------------------------
let g:indent_guides_enable_on_vim_startup = 1
let g:indent_guides_auto_colors = 0
autocmd VimEnter,Colorscheme * :hi IndentGuidesOdd guibg=red ctermbg=237
autocmd VimEnter,Colorscheme * :hi IndentGuidesEven guibg=green ctermbg=237
let g:indent_guides_start_level=1
let g:indent_guides_guide_size=1
let g:indent_guides_enable_on_vim_startup=1
let g:indent_guides_exclude_filetypes = ['markdown', 'html.mustache', 'help']"
"" Folding-related -----------------------------------------------------------
"hi Folded term=standout ctermfg=14 ctermbg=242 guifg=Cyan guibg=DarkGrey
set foldenable " 开始折叠
set foldmethod=syntax " 设置语法折叠
set foldcolumn=0 " 设置折叠区域的宽度
"setlocal foldlevel=1 " 设置折叠层数为
"set foldlevelstart=99 " 打开文件是默认不折叠代码
"set foldclose=all " 设置为自动关闭折叠
" 用空格键来开关折叠
nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc':'zo')<CR>
"" for python file
"" textwidth=80表示一行最多80个字符,
"" autoindent表示程序自动缩进,
"" fileformat=unix表示按照unix的文件格式存储。
au BufNewFile,BufRead *.py,
\ set tabstop=4 |
\ set softtabstop=4 |
\ set shiftwidth=4 |
\ set expandtab |
\ set autoindent |
\ set fileformat=unix |
\ set foldmethod=indent
"" visual-related -------------------------------------------------------
set showmatch " highlight matching [{()}]
set incsearch " search as characters are entered
set hlsearch " highlight matches
set selection=exclusive " visual delete 不包含下一个字符
nnoremap ,<space> :nohlsearch<CR> " ,<space> to close search hilight
"Press Space to turn off highlighting and clear any message already displayed.
" nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR>
let loaded_matchparen=1 " don't hightlight matching brackets/braces
set laststatus=2 " always show the status line
set incsearch " highlight search text as entered
set ignorecase " ignore case when searching
set smartcase " case sensitive only if capitals in search term
"set colorcolumn=80 " not available until Vim 7.3
set visualbell " shut the fuck up
set showcmd
set novisualbell
""高亮搜索
"hi Search cterm=NONE ctermfg=51 ctermbg=24
"hi Visual cterm=bold ctermfg=141 ctermbg=61
"" line-related ---------------------------------------------------------------
set number " line number on left
set relativenumber " show relative line number
set cursorline " highlight current line
" set nowrap " 不要折行"
nmap <Leader>v 0 " nmap LB 0
nmap <Leader>e $ " nmap LE $
set colorcolumn=80,120,140 " columns:80,100,120
let s:color_column_old = 0
function! s:ToggleColorColumn()
if s:color_column_old == 0
let s:color_column_old = &colorcolumn
"windo let &colorcolumn = 0
set colorcolumn=0
else
"windo let &colorcolumn=s:color_column_old
let &colorcolumn=s:color_column_old
let s:color_column_old = 0
endif
endfunction
" sidescroll: {0: 一次扩展半屏, 1: 续字符扩展(更流畅)}
set sidescroll=1
" 折行时,使 j/k 可以在折行内上下移动(而不是一次跳掉整行)
noremap <slient> <expr> j (v:count == 0 ? 'gj' : 'j')
noremap <slient> <expr> k (v:count == 0 ? 'gk' : 'k')
" NERDCommenter
" Align line-wise comment delimiters flush left instead of following code indentation
let g:NERDDefaultAlign = 'left'
" Add spaces after comment delimiters by default
let g:NERDSpaceDelims = 1
" Enable trimming of trailing whitespace when uncommenting
let g:NERDTrimTrailingWhitespace = 1
" Enable NERDCommenterToggle to check all selected lines is commented or not
let g:NERDToggleCheckAllLines = 1
nmap <Leader>c <Plug>NERDCommenterToggle<CR>
vmap <Leader>c <Plug>NERDCommenterToggle<CR>
" 高亮当前行 ================================================
"高亮当前行和行号
" -highlght 主要是用来配色的,包括语法高亮等个性化的配置。可以通过:h highlight,查看详细信息
" -CursorLine 和 CursorColumn 分别表示当前所在的行列
" -cterm 表示为原生vim设置样式,设置为NONE表示可以自定义设置。
" -ctermbg 设置终端vim的背景色
" -ctermfg 设置终端vim的前景色
" -guibg 和 guifg 分别是设置gvim的背景色和前景色,本人平时都是使用终端打开vim,所以只是设置终端下的样式
" 设置高亮行和列
"set cursorcolumn
set cursorline
"设置高亮效果
" Removes the underline causes by enabling cursorline:
" highlight clear CursorLine
" highlight CursorLine cterm=NONE ctermbg=black ctermfg=none guibg=NONE guifg=NONE
" highlight CursorColumn cterm=NONE ctermbg=black ctermfg=none guibg=NONE guifg=NONE
"highlight LineNr term=bold cterm=bold ctermfg=DarkGrey ctermbg=NONE gui=None guifg=DarkGrey guibg=NONE
"highlight CursorLineNR term=bold ctermfg=DarkGreen ctermbg=black cterm=bold
set linebreak " wrap long lines between words
"" =========================================================
" buffer-related --------------------------------------------------------------
" nnoremap <leader>bp :bp<CR>
" nnoremap <leader>bn :bn<CR>
" nnoremap <leader>db :bd<CR>
nnoremap bp :bp<CR>
nnoremap bn :bn<CR>
nnoremap bd :bd<CR>
"let g:interestingWordsDefaultMappings = 0
" file-releted operation ------------------------------------------------------
vnoremap <Leader>y "+y " 设置快捷键将选中文本块复制至系统剪贴板
nmap <Leader>p "+p " 设置快捷键将系统剪贴板内容粘贴至 vim
nmap <Leader>q :q<CR> " 定义快捷键关闭当前分割窗口
nmap <Leader>w :w<CR> " 定义快捷键保存当前窗口内容 vim:save and quit
nmap <Leader>wq :wa<CR>:q<CR> " 定义快捷键保存所有窗口内容并退出
"" Window-releted ------------------------------------------------------------
" 依次遍历子窗口
nnoremap nw <C-W><C-W>
" 跳转至右方的窗口
nnoremap <Leader>l <C-W>l
" 跳转至左方的窗口
nnoremap <Leader>h <C-W>h
" 跳转至上方的子窗口
nnoremap <Leader>k <C-W>k
nmap <Leader>k <C-W>k
" 跳转至下方的子窗口
nnoremap <Leader>j <C-W>j
" 定义快捷键在结对符之间跳转
nmap <Leader>M %
" nnoremap <silent> <Leader>+ :exe "vertical resize " . (winwidth(0) * 3/2)<CR>
" nnoremap <silent> <Leader>= :exe "vertical resize " . (winwidth(0) * 3/2)<CR>
" nnoremap <silent> <Leader>- :exe "vertical resize " . (winwidth(0) * 2/3)<CR>
nnoremap <silent> <Leader>= :exe "vertical resize +5"<CR>
nnoremap <silent> <Leader>- :exe "vertical resize -5"<CR>
" Window-releted
"max window
function! Zoom ()
" check if is the zoomed state (tabnumber > 1 && window == 1)
if tabpagenr('$') > 1 && tabpagewinnr(tabpagenr(), '$') == 1
let l:cur_winview = winsaveview()
let l:cur_bufname = bufname('')
tabclose
" restore the view
if l:cur_bufname == bufname('')
call winrestview(cur_winview)
endif
else
tab split
endif
endfunction
nmap <leader>z :call Zoom()<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" Coc
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" extensions
let g:coc_global_extensions = ['coc-tsserver', 'coc-json', 'coc-yaml',
\ 'coc-clangd', 'coc-pyright', 'coc-jedi',
\ 'coc-html', 'coc-css', 'coc-xml',
\ 'coc-emmet', 'coc-snippets',
\ 'coc-markdownlint', 'coc-highlight']
"" color
"hi CocMenuSel ctermbg=237 guibg=#13354A
" if hidden is not set, TextEdit might fail.
set hidden
" Some servers have issues with backup files, see #649
set nobackup
set nowritebackup
" Better display for messages
" 最下端显示的宽度,默认是 2,为了简洁页面,我设置成 1
set cmdheight=1
" You will have bad experience for diagnostic messages when it's default 4000.
set updatetime=300
" don't give |ins-completion-menu| messages.
set shortmess+=c
" always show signcolumns
set signcolumn=yes
function! CheckBackspace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use tab for trigger completion with characters ahead and navigate
" NOTE: There's always complete item selected by default, you may want to enable
" no select by `"suggest.noselect": true` in your configuration file
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config
inoremap <silent><expr> <TAB>
\ coc#pum#visible() ? coc#pum#next(1) :
\ CheckBackspace() ? "\<Tab>" :
\ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
" Make <CR> to accept selected completion item or notify coc.nvim to format
" <C-g>u breaks current undo, please make your own choice
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
" Use <c-space> to trigger completion.
inoremap <silent><expr> <c-space> coc#refresh()
" Use `[g` and `]g` to navigate diagnostics
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" Remap keys for gotos
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" Use K to show documentation in preview window
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
" Highlight symbol under cursor on CursorHold
autocmd CursorHold * silent call CocActionAsync('highlight')
" Remap for rename current word
nmap <leader>rn <Plug>(coc-rename)
" Remap for format selected region
xmap <leader>fm <Plug>(coc-format-selected)
nmap <leader>fm <Plug>(coc-format-selected)
augroup mygroup
autocmd!
" Setup formatexpr specified filetype(s).
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
" Update signature help on jump placeholder
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end
" Remap for do codeAction of selected region, ex: `<leader>aap` for current paragraph
xmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>a <Plug>(coc-codeaction-selected)
" Remap for do codeAction of current line
nmap <leader>ac <Plug>(coc-codeaction)
" Fix autofix problem of current line
nmap <leader>qf <Plug>(coc-fix-current)
" Create mappings for function text object, requires document symbols feature of languageserver.
xmap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap if <Plug>(coc-funcobj-i)
omap af <Plug>(coc-funcobj-a)
" Use <C-d> for select selections ranges, needs server support, like: coc-tsserver, coc-python
nmap <silent> <C-d> <Plug>(coc-range-select)
xmap <silent> <C-d> <Plug>(coc-range-select)
" Use `:Format` to format current buffer
command! -nargs=0 Format :call CocAction('format')
" Use `:Fold` to fold current buffer
command! -nargs=? Fold :call CocAction('fold', <f-args>)
" use `:OR` for organize import of current buffer
command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
" Add status line support, for integration with other plugin, checkout `:h coc-status`
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
" " Using CocList
" " Show all diagnostics
" nnoremap <silent> <space>a :<C-u>CocList diagnostics<cr>
" " Manage extensions
" nnoremap <silent> <space>e :<C-u>CocList extensions<cr>
" " Show commands
" nnoremap <silent> <space>c :<C-u>CocList commands<cr>
" " Find symbol of current document
" nnoremap <silent> <space>o :<C-u>CocList outline<cr>
" " Search workspace symbols
" nnoremap <silent> <space>s :<C-u>CocList -I symbols<cr>
" " Do default action for next item.
" nnoremap <silent> <space>j :<C-u>CocNext<CR>
" " Do default action for previous item.
" nnoremap <silent> <space>k :<C-u>CocPrev<CR>
" " Resume latest coc list
" nnoremap <silent> <space>p :<C-u>CocListResume<CR>
"" Use <Ctrl-p> to format documents with prettier
command! -nargs=0 Prettier :CocCommand prettier.formatFile
noremap <C-p> :Prettier<CR>
nmap <silent> <C-LeftMouse> <LeftMouse><Plug>(coc-definition)
" 查阅光标所在单词的信息并弹窗展示,如类型、关联注释等
nnoremap <Leader>k :call CocActionAsync('doHover')<CR>
" 执行代码格式化
nnoremap <Leader>F :call CocActionAsync('format')<CR>
" 查询函数静态调用树的入节点、出节点
nnoremap <Leader>i :CocCommand document.showIncomingCalls<CR>
nnoremap <Leader>o :CocCommand document.showOutgoingCalls<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" interestingwords ------------------------------------------------------------
"" highlight keywords
let g:interestingWordsGUIColors = ['#8CCBEA','#A4E57E','#FFDB72','#FF7272',
\ '#FFB3FF','#9999FF','#6F69AC','$95DAC1','#008700','#00af5f',
\ '#00d787','#0087af','#00d7af','#0087d7','#00d7d7','#0087ff',
\ '#5f8700','#5faf5f','#87875f','#8787af','#af875f','#d75f00','#d7af5f']
let g:interestingWordsTermColors = ['154','121','211','137','214','222',
\ '172','201','28','35','42','31','43','32','44','33','64',
\ '71','101','103','137','166','179']
let g:interestingWordsRandomiseColors = 1
let g:interestingWordsDefaultMappings = 0
nnoremap <silent> <leader>x :call InterestingWords('n')<cr>
vnoremap <silent> <leader>x :call InterestingWords('v')<cr>
nnoremap <silent> <leader>X :call UncolorAllWords()<cr>
nnoremap <silent> n :call WordNavigation(1)<cr>
nnoremap <silent> N :call WordNavigation(0)<cr>
" cpp/hpp file switch ---------------------------------------------------------
" *.cpp 和 *.h 间切换
nmap <silent> <Leader>sw :FSHere<cr>
" hiPairs --------------------------------------------------------------------
let g:matchup_matchparen_offscreen = {'method': 'popup'}
let g:hiPairs_hl_matchPair = { 'term' : 'underline,bold',
\ 'cterm' : 'bold',
\ 'ctermfg' : '0',
\ 'ctermbg' : '180',
\ 'gui' : 'bold',
\ 'guifg' : 'Black',
\ 'guibg' : '#D3B17D' }
let g:hiPairs_hl_unmatchPair = { 'term' : 'underline,italic',
\ 'cterm' : 'italic',
\ 'ctermfg' : '15',
\ 'ctermbg' : '12',
\ 'gui' : 'italic',
\ 'guifg' : 'White',
\ 'guibg' : 'Red' }
"Leaderf ----------------------------------------------------------------------
let g:Lf_ShortcutF = '<Leader><Leader>f'
let g:Lf_WorkingDirectoryMode = 'AF'
let g:Lf_RootMarkers = ['.git', '.svn', '.hg', '.project', '.root']
let g:Lf_WindowPosition = 'popup'
" Default fzf layout
" - down / up / left / right
let g:fzf_layout = { 'down': '~40%' }
" Customize fzf colors to match your color scheme
let g:fzf_colors =
\ { 'fg': ['fg', 'Normal'],
\ 'bg': ['bg', 'Normal'],
\ 'hl': ['fg', 'Comment'],
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
\ 'hl+': ['fg', 'Statement'],
\ 'info': ['fg', 'PreProc'],
\ 'prompt': ['fg', 'Conditional'],
\ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'],
\ 'spinner': ['fg', 'Label'],
\ 'header': ['fg', 'Comment'] }
" don't show the help in normal mode
let g:Lf_HideHelp = 1
let g:Lf_UseCache = 0
let g:Lf_UseVersionControlTool = 0
let g:Lf_IgnoreCurrentBufferName = 1
" popup mode
let g:Lf_PreviewInPopup = 1
let g:Lf_StlSeparator = { 'left': "\ue0b0", 'right': "\ue0b2", 'font': "DejaVu Sans Mono for Powerline" }
let g:Lf_PreviewResult = {'Function': 1, 'BufTag': 1 }
let g:Lf_CommandMap = {'<C-K>': ['<Up>'], '<C-j>': ['<Down>']}
let g:Lf_WindowHeight = 0.30
let g:Lf_StlColorscheme = 'powerline'
let g:Lf_PreviewResult = {
\ 'File': 0,
\ 'Buffer': 0,
\ 'Mru': 0,
\ 'Tag': 0,
\ 'BufTag': 1,
\ 'Function': 1,
\ 'Line': 1,
\ 'Colorscheme': 0,
\ 'Rg': 0,
\ 'Gtags': 0
\}
"<C-J>, <C-K> : navigate the result list.
noremap <leader>f :LeaderfSelf<cr>
" all buffers
noremap <leader>fb :<C-U><C-R>=printf("Leaderf buffer %s", "")<CR><CR>
" most recently used
noremap <leader>fm :<C-U><C-R>=printf("Leaderf mru %s", "")<CR><CR>
noremap <leader>fn :<C-U><C-R>=printf("Leaderf function %s", "")<CR><CR>
noremap <leader>ft :<C-U><C-R>=printf("Leaderf bufTag %s", "")<CR><CR>
noremap <leader>fl :<C-U><C-R>=printf("Leaderf line %s", "")<CR><CR>
"command! -bang -nargs=* Ag
"\ call fzf#vim#grep(
"\ 'ag --column --numbers --noheading --color --smart-case '.shellescape(<q-args>), 1,
"\ fzf#vim#with_preview(), <bang>0)
command! -bang -nargs=* Ag
\ call fzf#vim#ag(<q-args>,
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)
"ag
map <Leader>ag :Ag
" ag current word
map <Leader>aw :Ag <C-R><C-W><CR>
" fzf
noremap <C-B> :<C-U><C-R>=printf("Leaderf! rg --current-buffer -e %s ", expand("<cword>"))<CR>
noremap <C-F> :<C-U><C-R>=printf("Leaderf! rg -e %s ", expand("<cword>"))<CR>
" search visually selected text literally
xnoremap gf :<C-U><C-R>=printf("Leaderf! rg -F -e %s ", leaderf#Rg#visual())<CR>
noremap go :<C-U>Leaderf! rg --recall<CR>
" should use `Leaderf gtags --update` first
let g:Lf_GtagsAutoGenerate = 0
let g:Lf_GtagsGutentags = 1
let g:Lf_Gtagslabel = 'native-pygments'
" fzf -------------------------------------------------------------------------
" This is the default option:
" - Preview window on the right with 50% width
" - CTRL-/ will toggle preview window.
" - Note that this array is passed as arguments to fzf#vim#with_preview function.
" - To learn more about preview window options, see `--preview-window` section of `man fzf`.
let g:fzf_preview_window = ['right:50%', 'ctrl-/']
" Preview window on the upper side of the window with 40% height,
" hidden by default, ctrl-/ to toggle
let g:fzf_preview_window = ['up:40%:hidden', 'ctrl-/']
" Empty value to disable preview window altogether
let g:fzf_preview_window = []
" [Buffers] Jump to the existing window if possible
let g:fzf_buffers_jump = 1
" [[B]Commits] Customize the options used by 'git log':
let g:fzf_commits_log_options = '--graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"'
" [Tags] Command to generate tags file
let g:fzf_tags_command = 'ctags -R'
" [Commands] --expect expression for directly executing the command
let g:fzf_commands_expect = 'alt-enter,ctrl-x'
" Mapping selecting mappings
nmap <leader><tab> <plug>(fzf-maps-n)
xmap <leader><tab> <plug>(fzf-maps-x)
omap <leader><tab> <plug>(fzf-maps-o)
nmap <C-f> :Files<CR>
nmap <C-b> :Buffers<CR>
nmap <leader>ff :Files<CR>
let g:fzf_action = {'ctrl-e':'edit', "ctrl-t":"tab split", "ctrl-s": "split", "ctrl-v": "vsplit"}
" Insert mode completion
imap <c-x><c-k> <plug>(fzf-complete-word)
imap <c-x><c-f> <plug>(fzf-complete-path)
imap <c-x><c-l> <plug>(fzf-complete-line)
" quickui ---------------------------------------------------------------------
"==============================================================================
"vim-quickui
" clear all the menus
call quickui#menu#reset()
let g:quickui_color_scheme = 'gruvbox'
" install a 'File' menu, use [text, command] to represent an item.
call quickui#menu#install('&File', [
\ [ "&New File\tCtrl+n", 'echo 0' ],
\ [ "&Open File\t(F3)", 'echo 1' ],
\ [ "&Close", 'echo 2' ],
\ [ "--", '' ],
\ [ "&Save\tCtrl+s", 'echo 3'],
\ [ "Save &As", 'echo 4' ],
\ [ "Save All", 'echo 5' ],
\ [ "--", '' ],
\ [ "E&xit\tAlt+x", 'echo 6' ],
\ ])
" items containing tips, tips will display in the cmdline
call quickui#menu#install('&Edit', [
\ [ '&Copy', 'echo 1', 'help 1' ],
\ [ '&Paste', 'echo 2', 'help 2' ],
\ [ '&Find', 'echo 3', 'help 3' ],
\ ])
" script inside %{...} will be evaluated and expanded in the string
call quickui#menu#install("&Option", [
\ ['Set &Spell %{&spell? "Off":"On"}', 'set spell!'],
\ ['Set &Cursor Line %{&cursorline? "Off":"On"}', 'set cursorline!'],
\ ['Set &Paste %{&paste? "Off":"On"}', 'set paste!'],
\ ])
" register HELP menu with weight 10000
call quickui#menu#install('H&elp', [
\ ["&Cheatsheet", 'help index', ''],
\ ['T&ips', 'help tips', ''],
\ ['--',''],
\ ["&Tutorial", 'help tutor', ''],
\ ['&Quick Reference', 'help quickref', ''],
\ ['&Summary', 'help summary', ''],
\ ], 10000)
call quickui#menu#install('&C/C++', [
\ [ '&Compile', 'echo 1' ],
\ [ '&Run', 'echo 2' ],
\ ], '<auto>', 'c,cpp')
" enable to display tips in the cmdline
let g:quickui_show_tip = 1
" hit space twice to open menu
noremap <Leader><Leader>m :call quickui#menu#open()<cr>
function! TermExit(code)
echom "terminal exit code: ". a:code
endfunc
let opts = {'w':120, 'h':20, 'col':30, 'line':10, 'callback':'TermExit'}
let opts.title = 'Terminal Popup'
"打开终端
nnoremap <Leader><Leader>t :call quickui#terminal#open('zsh', opts)<cr>
"切换buffer
"Then hjkl to navigate, enter/space to switch buffer and ESC/CTRL+[ to quit: ]
"If there are many buffers listed, you can use / or ? to search, and n or N to jump to the next / previous match.
"Usage:
"
"- j/k: navigate.
"- ESC/CTRL+[: quit
"- Enter: open with switchbuf rules (override with g:quickui_switch_enter).
"- Space: open with switchbuf rules (override with g:quickui_switch_space).
"- CTRL+e: edit in current window.
"- CTRL+x: open in a new split.
"- CTRL+]: open in a new vertical split.
"- CTRL+t: open in a new tab.
"- CTRL+g: open with :drop command.
"- /: search.
"- ?: search backwards.
nnoremap <Leader><Leader>b :call quickui#tools#list_buffer('e')<cr>
"function list
" nnoremap <space><space>f :call quickui#tools#list_function()<cr>
" Vim-repl -------------------------------------------------------------------
" let g:repl_program = {
" \ 'python': 'ipython',
" \ 'default': 'bash',
" \ 'r': 'R',
" \ 'lua': 'lua',
" \ }
let g:repl_program = {
\ 'python': 'zsh',
\ 'default': 'zsh',
\ 'r': 'R',
\ 'lua': 'lua',
\ }
let g:repl_width = 120 "REPL windows width"
let g:repl_predefine_python = {
\ 'numpy': 'import numpy as np',
\ 'matplotlib': 'from matplotlib import pyplot as plt'
\ }
let g:repl_python_auto_import = 1
let g:repl_cursor_down = 1
let g:repl_python_automerge = 1
let g:repl_ipython_version = '7'
" nnoremap <leader>t :REPLToggle<Cr>
nnoremap <leader>t :REPLToggle<Cr>
" autocmd Filetype python nnoremap <F12> <Esc>:REPLDebugStopAtCurrentLine<Cr>
"autocmd Filetype python nnoremap <F10> <Esc>:REPLPDBN<Cr>
"autocmd Filetype python nnoremap <F11> <Esc>:REPLPDBS<Cr>
"let g:repl_width = None "窗口宽度
"let g:repl_height = None "窗口高度
" let g:sendtorepl_invoke_key = "<leader>r" "传送代码快捷键,默认为<leader>w
" ref: http://stackoverflow.com/questions/598113/can-terminals-detect-shift-enter-or-control-enter
let g:sendtorepl_invoke_key = "<CR>" "传送代码快捷键,默认为<leader>w
let g:repl_position = 3 "0表示出现在下方,1表示出现在上方,2在左边,3在右边
let g:repl_stayatrepl_when_open = 0 "打开REPL时是回到原文件(1)还是停留在REPL窗口中(0)"
let g:repl_console_name = 'Vim-REPL'
tnoremap <C-h> <C-w><C-h>
tnoremap <C-j> <C-w><C-j>
tnoremap <C-k> <C-w><C-k>
tnoremap <C-l> <C-w><C-l>
" tnoremap <C-n> <C-w>N
tnoremap <ScrollWheelUp> <C-w>Nk
tnoremap <ScrollWheelDown> <C-w>Nj
" Fastfold --------------------------------------------------------------------
nmap zuz <Plug>(FastFoldUpdate)
let g:fastfold_savehook = 1
let g:fastfold_fold_command_suffixes = ['x','X','a','A','o','O','c','C']
let g:fastfold_fold_movement_commands = ['z', '[z', 'zj', 'zk']
let g:fastfold_fold_command_suffixes = ['x','X','a','A','o','O','c','C','r','R','m','M','i','n','N']
" Highlight ------------------------------------------------------------------
" Highlight TODO, FIXME, NOTE, etc.
if has("autocmd")
if v:version > 701
autocmd Syntax * call matchadd('Todo', '\W\zs\(TODO\|FIXME\|CHANGED\|BUG\|HACK\)')
autocmd Syntax * call matchadd('Debug', '\W\zs\(NOTE\|Note:\|INFO\|IDEA\)')
endif
endif
" abb ------------------------------------------------------------------------
vmap \a :source ~/.vim/abb.vim<CR>
nnoremap \a :source ~/.vim/abb.vim<CR>
"Rainbow ---------------------------------------------------------------------
""au FileType c,cpp,objc,objcpp call rainbow#load()
let g:rainbow_active = 1
let g:rainbow_load_separately = [
\ [ '*' , [['(', ')'], ['\[', '\]'], ['{', '}']] ],
\ [ '*.tex' , [['(', ')'], ['\[', '\]']] ],
\ [ '*.cpp' , [['(', ')'], ['\[', '\]'], ['{', '}']] ],
\ [ '*.{html,htm}' , [['(', ')'], ['\[', '\]'], ['{', '}'], ['<\a[^>]*>', '</[^>]*>']] ],
\ ]
let g:rainbow_guifgs = ['RoyalBlue3', 'DarkOrange3', 'DarkOrchid3', 'FireBrick']
let g:rainbow_ctermfgs = ['lightblue', 'lightgreen', 'yellow', 'red', 'magenta']
"UltiSnips -------------------------------------------------------------------
"Put under .vim/UltiSnips
let g:UltiSnipsSnippetDirectories=["UltiSnips", "MyUltiSnips"]
" Trigger configuration. You need to change this to something other than <tab> if you use one of the following:
" - https://github.com/Valloric/YouCompleteMe
" - https://github.com/nvim-lua/completion-nvim
" let g:UltiSnipsExpandTrigger="<leader><tab>"
" let g:UltiSnipsJumpForwardTrigger="<leader><tab>"
" let g:UltiSnipsJumpBackwardTrigger="<leader><tab>"
let g:UltiSnipsExpandTrigger="<leader>u"
let g:UltiSnipsJumpForwardTrigger="<leader>s"
let g:UltiSnipsJumpBackwardTrigger="<leader>s"
let g:UltiSnipsListSnippets="<c-l>"
" If you want :UltiSnipsEdit to split your window.
let g:UltiSnipsEditSplit="vertical"
|