-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
1006 lines (892 loc) · 36.7 KB
/
vimrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
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
" Check for vim-plug "
""""""""""""""""""""""""
" Check for vim-plug if not exist download it
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
augroup vimplug
au!
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
augroup END
endif
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Pluglist "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
call plug#begin('~/.vim/plugged')
" Need attention
Plug 'takac/vim-hardtime'
" System
" Plug 'lyokha/vim-xkbswitch', {'as': 'xkbswitch'} " fix for cn change en
Plug 'vim-scripts/LargeFile' " Fast Load for Large files
Plug 'kana/vim-textobj-indent'
Plug 'kana/vim-textobj-user'
Plug 'kana/vim-textobj-syntax'
Plug 'kana/vim-textobj-function', { 'for':['c', 'cpp', 'vim', 'java', 'python'] }
Plug 'sgur/vim-textobj-parameter'
Plug 'michaeljsmith/vim-indent-object' " used for align
Plug 'terryma/vim-smooth-scroll' " smooth scroll
Plug 'tpope/vim-obsession'
" Coding
Plug 'neoclide/coc.nvim', {'tag': '*', 'do': './install.sh'}
Plug 'ludovicchabant/vim-gutentags' " auto generate tags
Plug 'w0rp/ale' " Syntax Check
Plug 'SirVer/ultisnips' " snippets
Plug 'VDeamoV/vim-snippets'
Plug 'tpope/vim-commentary'
Plug 'Raimondi/delimitMate' " Brackets Jump 智能补全括号和跳转
" 补全括号 shift+tab出来
" Plug 'jiangmiao/auto-pairs' " insert or delete pairs
Plug 'vim-scripts/matchit.zip' " % g% [% ]% a%
Plug 'andymass/vim-matchup' " extence
Plug 'octol/vim-cpp-enhanced-highlight', {'for':['c', 'cpp']}
Plug 'easymotion/vim-easymotion' " trigger with <leader><leader>+s/w/gE
Plug 'skywind3000/asyncrun.vim' " Compile
Plug 'godlygeek/tabular' " align text
Plug 'tpope/vim-surround' " change surroundings
" c[ange]s[old parttern] [new partten]
" ds[partten]
" ys(iww)[partten] / yss)
Plug 'tpope/vim-repeat' " for use . to repeat for surround
Plug 'chxuan/tagbar' " show params and functions
" Writing Blog
Plug 'hotoo/pangu.vim', {'for': ['markdown']} "to make your document better
Plug 'godlygeek/tabular', {'for': ['markdown']}
Plug 'plasticboy/vim-markdown', {'for': ['markdown']}
Plug 'mzlogin/vim-markdown-toc', {'for': ['markdown']}
" :GenTocGFM/:GenTocRedcarpet
":UpdateToc 更新目录
Plug 'dhruvasagar/vim-table-mode', {'for': ['markdown']}
"<leader>tm to enable
"|| in the insert mode to create a horizontal line
"| match the | up row
"<leader>tdd to delete the row
"<leader>tdc to delete the coloum
"<leader>tt to change the exist text to format table
Plug 'xuhdev/vim-latex-live-preview', {'for': ['tex']} " Use when you work with cn
Plug 'lervag/vimtex', {'for': ['tex']} " English is okay, fail with cn
"FileManage
Plug 'scrooloose/nerdtree'
Plug 'Xuyuanp/nerdtree-git-Plugin'
Plug 'tiagofumo/vim-nerdtree-syntax-highlight'
Plug 'mhinz/vim-startify'
Plug 'justinmk/vim-dirvish'
Plug 'kristijanhusak/vim-dirvish-git'
" Apperance
Plug 'itchyny/lightline.vim'
Plug 'flazz/vim-colorschemes'
Plug 'Yggdroot/indentLine' " Show indent line
Plug 'kshenoy/vim-signature' " Visible Mark
Plug 'junegunn/vim-slash' " clean hightline after search
Plug 'luochen1990/rainbow' " multi color for Parentheses
Plug 'therubymug/vim-pyte' " theme pyte
Plug 'vim-scripts/mayansmoke'
" https://github.com/vim-scripts/mayansmoke
Plug 'vim-scripts/peaksea'
Plug 'haishanh/night-owl.vim'
" Github
Plug 'tpope/vim-fugitive'
Plug 'mattn/gist-vim'
Plug 'mattn/webapi-vim'
Plug 'junegunn/vim-github-dashboard', { 'on': ['GHDashboard', 'GHActivity'] } " visit github in vim
Plug 'junegunn/gv.vim'
Plug 'airblade/vim-gitgutter' " [c ]c jump to prev/next change [C ]C
" Search
Plug 'tpope/vim-abolish' "增强版的substitue
":%S/{man,dog}/{dog,man}/g 替换man和dog的位置
Plug 'Yggdroot/LeaderF' " Ultra search tools
Plug 'mileszs/ack.vim' " Use to search pattern in files
call plug#end()
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Mappings "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Caution: Mapping should place before PluginConfigure
let mapleader=' '
nmap . .`[
nmap <leader>w :w<CR>
nmap <leader>q :q<CR>
nnoremap <Leader>eg :e ++enc=gbk<CR>
nnoremap <Leader>eu :e ++enc=utf8<CR>
" nnoremap <leader>sl :set list!<CR> " quick config to see or not see special character
nnoremap <leader>ll :set conceallevel=0<CR> " quick change conceal mode
nnoremap <leader>ev :tabe $MYVIMRC<CR> " Quickly edit/reload the vimrc file
" show HEX and return
nnoremap <Leader>xd :%!xxd<CR>
nnoremap <Leader>xr :%!xxd -r<CR>
" Window control
nnoremap <leader>t :tabe<CR> " open a new tab
nnoremap <leader>v :vnew<CR> " close tab
nnoremap <leader>tq :tabclose<CR>
" use ]+space create spaceline
nnoremap [<space> :<c-u>put! =repeat(nr2char(10), v:count1)<cr>'[
nnoremap ]<space> :<c-u>put =repeat(nr2char(10), v:count1)<cr>
" Use <C-L> to clear the highlighting of :set hlsearch
if maparg('<C-L>', 'n') ==# ''
nnoremap <silent> <C-L> :nohlsearch<C-R>=has('diff')?'<Bar>diffupdate':''<CR><CR><C-L>
endif
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" PluginConfigure "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"pathogen
execute pathogen#infect()
" tpope/vim-obsession
" :Obsession ~/.vim/obsessions/
" :source ~/.vim/obsessions/Session.vim
command! -bang Sesh call Sesh(<bang>0)
function! Sesh(bang)
let l:file = $HOME . '/.vim/obsessions/Session.vim'
let l:isTracking = !empty(ObsessionStatus('tracking', '')) " true for both off and pused
if (a:bang) " replace persisted session
if (l:isTracking)
Obsession!
endif
if (filereadable(l:file))
call delete(l:file)
endif
exec 'Obsession ' . l:file
else " restore session if possible or start tracking current
if (!l:isTracking)
if (filereadable(l:file))
exec 'source ' . l:file
else
exec 'Obsession ' . l:file
endif
else
echom 'already tracking'
endif
endif
endfunction
" coc.nvim
set shell=/bin/zsh
let g:coc_status_error_sign='E'
let g:coc_status_warning_sign='W'
" coc-python
" Remap key for gotos.
nmap <leader>jd <Plug>(coc-definition)
" nmap <leader>gy <Plug>(coc-type-definition)
" nmap <leader>gi <Plug>(coc-implementation)
" nmap <leader>gr <Plug>(coc-references)
" Highlight symbol under cursor on CursorHold
autocmd CursorHold * silent call CocActionAsync('highlight')
" Remap for format selected region
xmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format-selected)
" Fix autofix problem of current line
nmap <leader>qf <Plug>(coc-fix-current)
" rainbow
let g:rainbow_active = 1
" ack
if executable('ag')
let g:ackprg = 'ag --vimgrep'
endif
" vim-smooth-scroll
" Distance Duration Speed
noremap <silent> <c-u> :call smooth_scroll#up(&scroll, 8, 2)<CR>
noremap <silent> <c-d> :call smooth_scroll#down(&scroll, 8, 2)<CR>
noremap <silent> <c-b> :call smooth_scroll#up(&scroll*2, 8, 4)<CR>
noremap <silent> <c-f> :call smooth_scroll#down(&scroll*2, 8, 4)<CR>
" junegunn/vim-slash
noremap <plug>(slash-after) zz
if has('timers')
" Blink 2 times with 50ms interval
noremap <expr> <plug>(slash-after) slash#blink(2, 50)
endif
" vim-hardtime
let g:hardtime_default_on = 0
let g:hardtime_timeout = 500
let g:hardtime_ignore_quickfix = 1
"easymotion
" s{char}{char} to move to {char}{char}
nmap <leader>s <Plug>(easymotion-overwin-f2)
" Move to line
map L <Plug>(easymotion-bd-jk)
nmap <leader>L <Plug>(easymotion-overwin-line)
" Move to word
map W <Plug>(easymotion-bd-w)
nmap <leader>W <Plug>(easymotion-overwin-w)
"asyncrun
" auto open quickfix window, height = 6
let g:asyncrun_open=6
let g:asyncrun_bell=1
let g:asyncrun_rootmarks = ['.svn', '.git', '.root', '_darcs' , 'build.xml', 'Makefile']
nnoremap <F10> : call asyncrun#quickfix_toggle(10)<CR>
" commnent for I barely use cpp for now
" nnoremap <silent> <F9> : AsyncRun gcc -Wall -O2 "$(VIM_FILEPATH)" -o "$(VIM_FILEDIR)/$(VIM_FILENOEXT)" <CR>
" nnoremap <silent> <F5> : AsyncRun -raw -cwd=$(VIM_FILEDIR) "$(VIM_FILEDIR)/$(VIM_FILENOEXT)" <CR>
" nnoremap <silent> <F8> : AsyncRun -cwd=<root> -mode=4 make run <CR>
nnoremap <silent> <F7> : AsyncRun -cwd=<root> make run<CR>
"vim-latex-live-preview
autocmd Filetype tex setl updatetime=1
let g:livepreview_previewer = 'open -a Preview'
"vimtex
let g:tex_flavor='latex'
let g:vimtex_view_method='skim'
let g:vimtex_quickfix_mode=0
set conceallevel=1
let g:tex_conceal='abdmg'
"mhinz/vim-startify
let g:startify_list_order = [
\ [' Bookmarks'], 'bookmarks',
\ [' MRU'], 'files' ,
\ [' MRU '.getcwd()], 'dir',
\ [' Sessions'], 'sessions',
\ ]
let g:startify_bookmarks = [
\ '~/Desktop',
\ '~/Documents/Coding/Test']
let g:startify_change_to_dir = 0
let g:startify_enable_special = 0
let g:startify_files_number = 8
let g:startify_session_autoload = 1
let g:startify_session_delete_buffers = 1
let g:startify_session_persistence = 1
let g:startify_use_env = 1
"scrooloose/nerdtree
nnoremap <leader>ne :NERDTreeFind<CR>
nnoremap <leader>nt :NERDTreeToggle<CR>
let g:NERDTreeShowLineNumbers=1
let NERDTreeAutoCenter=1
let g:NERDTreeChDirMode=2
let NERDTreeWinPos="left"
let g:nerdtree_tabs_open_on_console_startup=1
let g:NERDTreeShowBookmarks=1
let g:NERDTreeIgnore=['\.pyc','\~$','\.swp','\.DS_Store']
"vim-table-mode
let g:table_mode_corner = '|'
let g:table_mode_delimiter = ' '
let g:table_mdoe_verbose = 0
let g:table_mode_auto_align = 0
"autocmd FileType markdown TableModeEnable
"vim-markdown
let g:vim_markdown_math=1
"vim-markdown-toc
let g:vmt_auto_update_on_save=1 "update toc when save
let g:vmt_dont_insert_fence=0 "if equals to 1, can't update toc when save
"gist-vim
let github_user='VDeamoV'
"vim-gutentags
" gutentags 搜索工程目录的标志,碰到这些文件/目录名就停止向上一级目录递归
let g:gutentags_project_root = ['.root', '.svn', '.git', '.hg', '.project']
" 所生成的数据文件的名称
let g:gutentags_ctags_tagfile = '.tags'
" 将自动生成的 tags 文件全部放入 ~/.cache/tags 目录中,避免污染工程目录
let s:vim_tags = expand('~/.cache/tags')
let g:gutentags_cache_dir = s:vim_tags
" 配置 ctags 的参数
let g:gutentags_ctags_extra_args = ['--fields=+niazS', '--extra=+q']
let g:gutentags_ctags_extra_args += ['--c++-kinds=+px']
let g:gutentags_ctags_extra_args += ['--c-kinds=+px']
" 检测 ~/.cache/tags 不存在就新建
if !isdirectory(s:vim_tags)
silent! call mkdir(s:vim_tags, 'p')
endif
"Yggdroot/indentLine
let g:indentLine_enabled=1
let g:indentLine_char_list = ['|', '¦', '┆', '┊']
"LeaderF
let g:Lf_ShortcutF = '<c-p>'
let g:Lf_ShortcutB = '<m-n>'
" execute "set <A-m>=\em,"
" execute "set <A-b>=\eb"
" execute "set <A-m>=\em"
noremap <c-n> :LeaderfMru<cr>
noremap <A-m> :LeaderfFunction!<cr>
noremap <A-b> :LeaderfBuffer<cr>
" noremap <A-m> :LeaderfTag<cr>
let g:Lf_StlSeparator = { 'left': '', 'right': '', 'font': '' }
let g:Lf_RootMarkers = ['.project', '.root', '.svn', '.git']
let g:Lf_WorkingDirectoryMode = 'Ac'
let g:Lf_WindowHeight = 0.30
let g:Lf_CacheDirectory = expand('~/.vim/cache')
let g:Lf_ShowRelativePath = 0
let g:Lf_HideHelp = 1
let g:Lf_StlColorscheme = 'powerline'
let g:Lf_PreviewResult = {'Function':0, 'BufTag':0}
"echodoc
"LightLine
let g:lightline = {
\ 'colorscheme': 'seoul256',
\ 'active': {
\ 'left': [
\ [ 'mode', 'paste' ],
\ [ 'filename', 'modified' ],
\ [ 'gitbranch', 'git_changes' ],
\ [ 'cocstatus' ]
\ ],
\ 'right': [
\ ['lineinfo'],
\ ['percent'],
\ ['readonly', 'linter_warnings', 'linter_errors', 'linter_ok'],
\ ['obsession'],
\ ]
\ },
\ 'component_function': {
\ 'match_count': 'MatchCountStatusline',
\ 'obsession': 'LightlineObsessionStatus',
\ 'gitbranch': 'fugitive#head',
\ 'git_changes': 'LightLineChanges',
\ 'cocstatus': 'coc#status'
\ },
\ 'component_expand': {
\ 'linter_warnings': 'LightlineLinterWarnings',
\ 'linter_errors': 'LightlineLinterErrors',
\ 'linter_ok': 'LightlineLinterOK',
\ },
\ 'component_type': {
\ 'readonly': 'error',
\ 'linter_warnings': 'warning',
\ 'linter_errors': 'error'
\ },
\ 'separator': {
\ 'left': '',
\ 'right': ''
\ },
\ 'enable': {
\ 'statusline': 1,
\ 'tabline': 0
\ }
\ }
function! LightlineObsessionStatus()
if exists('*ObsessionStatus')
return ObsessionStatus('session', 'session paused')
endif
endfunction
function! LightLineChanges()
let l:hunkSummary = v:null
if exists('*GitGutterGetHunkSummary')
let l:hunkSummary = GitGutterGetHunkSummary()
elseif exists('g:loaded_signify') && sy#buffer_is_active()
let l:hunkSummary = sy#repo#get_stats()
endif
if (empty(l:hunkSummary))
return ''
else
let [ l:added, l:modified, l:removed ] = l:hunkSummary
let l:total = (l:added + l:modified + l:removed)
let l:output = ''
if (l:added != 0)
let l:output .= printf('+%d ', l:added)
endif
if (l:modified != 0)
let l:output .= printf('~%d ', l:modified)
endif
if (l:removed != 0)
let l:output .= printf('-%d ', l:removed)
endif
return '(' . l:output . ')'
endif
endfunction
function! LightlineLinterWarnings() abort
if (&readonly)
return ''
endif
let l:counts = ale#statusline#Count(bufnr(''))
let l:all_errors = l:counts.error + l:counts.style_error
let l:all_non_errors = l:counts.total - l:all_errors
return l:all_non_errors == 0 ? '' : printf('%d ▲', l:all_non_errors)
endfunction
function! LightlineLinterErrors() abort
if (&readonly)
return ''
endif
let l:counts = ale#statusline#Count(bufnr(''))
let l:all_errors = l:counts.error + l:counts.style_error
let l:all_non_errors = l:counts.total - l:all_errors
return l:all_errors == 0 ? '' : printf('%d ✗', l:all_errors)
endfunction
function! LightlineLinterOK() abort
if (&readonly)
return ''
endif
let l:counts = ale#statusline#Count(bufnr(''))
let l:all_errors = l:counts.error + l:counts.style_error
let l:all_non_errors = l:counts.total - l:all_errors
return l:counts.total == 0 ? '✓' : ''
endfunction
augroup ale_stuff
au!
autocmd User ALELint call s:MaybeUpdateLightline()
augroup END
function! s:MaybeUpdateLightline()
" Update and show lightline but only if it's visible (e.g., not in Goyo)
if exists('#lightline')
call lightline#update()
end
endfunction
"vim-xkbswitch
" let g:XkbSwitchEnabled = 1
" let g:XkbSwitchIMappings = ['cn']
" let g:XkbSwitchIMappingsTr = {'cn': {'<': '', '>': ''}}
"SirVer/ultisnips
"customize python and keymapping
"ref:https://gist.github.com/lencioni/dff45cd3d1f0e5e23fe6
"ref:https://stackoverflow.com/questions/14896327/ultisnips-and-youcompleteme
let g:UltiSnipsUsePythonVersion = 3
let g:UltiSnipsExpandTrigger = "<tab>"
let g:UltiSnipsListSnippets = "<c-l>"
let g:UltiSnipsJumpForwardTrigger = "<c-j>"
let g:UltiSnipsJumpBackwardTrigger = "<c-k>"
let g:snips_author = "VDeamoV"
let g:snips_email = "vincent.duan95@outlook.com"
let g:snips_github = "https://github.com/VDeamoV"
"w0rp/ale
let g:ale_linters_explicit = 1
let g:ale_completion_delay = 500
let g:ale_echo_delay = 20
let g:ale_lint_delay = 500
let g:ale_echo_msg_format = '[%linter%] %code: %%s'
let g:ale_lint_on_text_changed = 'normal'
let g:ale_lint_on_insert_leave = 1
let g:ale_c_gcc_options = '-Wall -O2 -std=c99'
let g:ale_cpp_gcc_options = '-Wall -O2 -std=c++14'
let g:ale_c_cppcheck_options = ''
let g:ale_cpp_cppcheck_options = ''
let g:ale_sign_eror = 'E'
let g:ale_sign_warning = 'W'
let g:ale_linters = {
\ 'python': ['pylint'],
\ 'tex': ['lacheck'],
\ 'swift': ['swiftlint'],
\ 'markdown': ['markdownlint'],
\ 'cpp': ['gcc', 'cpplint'],
\ 'c': ['gcc', 'cpplint'],
\ 'java': ['javac','google-java-format'],
\}
let g:ale_go_langserver_executable = 'gopls'
let g:ale_fixers = {
\ '*': ['remove_trailing_lines','trim_whitespace' ],
\ 'python': ['autopep8']
\}
"let g:ale_fix_on_save = 1 "auto Sava
"Use :ALEFix to fix
let g:ale_list_window_size = 5
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Basic Settings "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set nocompatible " not compatible for vi
set nospell " close spell examine
set number " show number
set relativenumber "show relative line number
set hlsearch " Highlight the matching part
set incsearch " Shows the match while typing
set ignorecase
set smartcase
set showmatch " Show matching brackets/parenthesis
set encoding=utf-8 " configure the encoding
set termencoding=utf-8 " it will choose the first right configure to use
set fileencodings=utf-8,gbk,utf-16le,cp1252,iso-8859-15,ucs-bom
set fileformats=unix,dos,mac
set linespace=0 " No extra spaces between rows
set confirm " Confirm before vim exit
set nobackup
set noswapfile
set lazyredraw " don't update the display while executing macros
set backspace=eol,start,indent " use backspace for delete space line
set ruler " show the cursor's position
set nomodeline " disable mode lines (security measure)
set noshowmode " do not show Insert, We already have it in lightline
set mouse=a " allow mouse select and etc operation
set autoindent " config the indent
set smartindent
set smarttab
set copyindent
set tabstop=2 softtabstop=2 shiftwidth=2 expandtab
set history=1000 " save 1000 cmd
set timeoutlen=500 " give u 500 time to react for cmd
set list " show the special character
set guioptions=e "only show guitablabel
set autoread
set autowrite
set autowriteall " Auto-write all file changes
set iskeyword-=_,.,=,-,:,
set guifont=Source\ Code\ Pro\ for\ Powerline:h16
set switchbuf=useopen " reveal already opened files from the
" quickfix window instead of opening new buffers
set wildmenu
set cursorcolumn " highlight column
set cursorline " highlight row
" set wildmode=list:longest,full
if has('nvim') " Use floating windows to complete the commond, only neovim support
set wildoptions=pum
set termguicolors " With out this settings, transparable float-win will not work normally
set pumblend=30 " Let floatingwindow to be transparable
elseif
set wildmode=list:longest,full " Set list to show completeopt, however it will lead to disfunc for floating windows
endif
set nowrap " Do not wrap long lines
set whichwrap=b,s,h,l,<,>,>h,[,] " Backspace and cursor keys wrap too
set t_Co=256 " number of colors
"set autochdir "disable for leadf
set laststatus=2 " always show statusline
set showtabline=2 " always show tabline
set hidden
set display+=lastline
set noerrorbells novisualbell t_vb= " cancel the annoying bell
set belloff=all
set showcmd " Show partial commands in status line and
" Selected characters/lines in visual mode
set viewoptions=folds,options,cursor,unix,slash " Better Unix / Windows compatibility
set virtualedit=onemore " used with caution of breaking plugins
set completeopt=menuone,menu,preview,longest
set tags=./tags;/,~/.vimtags
set dictionary+=/usr/share/dict/words " autocompletion with dictionary help
set dictionary+=~/.vim/dict/
set statusline+=%*
set statusline+=%#warningmsg#
set shortmess+=filmnrxoOtT " Abbrev. of messages (avoids 'hit enter')
set undofile " enable undo after close the file
set undodir=$HOME/.vim/undo
set undolevels=1000
set undoreload=10000
filetype on
filetype plugin indent on
if has('syntax')
syntax enable
endif
if has('clipboard')
if has('unnamedplus') " When possible use + register for copy-paste
set clipboard=unnamed,unnamedplus
else " On mac and Windows, use * register for copy-paste
set clipboard=unnamed
endif
endif
set wildignore=*.o,*~,*.pyc,*.swp,*.bak,*.class,*.DS_Store " vim will ignore them
if has('win16') || has('win32')
set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store
else
set wildignore+=.git\*,.hg\*,.svn\*
endif
if !&scrolloff " Minimum lines to keep above and below cursor
set scrolloff=1
endif
if !&sidescrolloff
set scrolloff=5
endif
set colorcolumn=+1 " color the 81 column for warning
" let &colorcolumn=join(range(81,999),',')
" let &colorcolumn='80,'.join(range(120,999),',')
" fold config
" foldmethod [diff, expr, indent, manual, marker, syntax]
" diff show the diff between unfold and fold
" expr use `foldexpr` to config fold logic
" indent fold base on indent
" manual use zf zF or :Fold to fold, zfa(,
" :mkview to save
" :loadview to reload
" mark ....
" syntax
set foldmethod=manual
set foldlevel=99
set foldlevelstart=99
" nnoremap <space> za
" vnoremap <space> zf
let gitroot = substitute(system('git rev-parse --show-toplevel'),'[\n\r]', '', 'g') " Make tags placed in .git/tags file available in all levels of a repository
if gitroot != ''
let &tags = &tags . ',' . gitroot . '/.git/tags'
endif
" wrap config (not recommend
" formation options
" default is tcq
" t: 根据 textwidth 自动折行
" c: 在(程序源代码中的)注释中自动折行,插入合适的注释起始字符
" r: 插入模式下在注释中键入回车时,插入合适的注释起始字符
" q: 允许使用"gq"命令对注释进行格式化;
" n: 识别编号列表,编号行的下一行的缩进由数字后的空白决定(与“2”冲突,需要“autoindent”);
" 2: 使用一段的第二行的缩进来格式化文本;
" l: 在当前行长度超过 textwidth 时,不自动重新格式化;
" m: 在多字节字符处可以折行,对中文特别有效(否则只在空白字符处折行);
" M: 在拼接两行时(重新格式化,或者是手工使用“J”命令),如果前一行的结尾或后一行的开头是多字节字符,则不插入空格,非常适合中文
"
" set textwidth=80 "最大字符长度
" set formatoptions+=t
set formatoptions-=t "disable wrap
" set formatoptions-=l " wrap long lines
" if v:version > 703 || v:version == 703 && has('patch541')
" set formatoptions+=j " Delete comment chars when join comment lines
" endif
" set wrapmargin=2 " 2 chars wrap margin from the right window border, hard wrap
" for tmux
if exists('$TMUX')
set term=screen-256color
endif
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Functions "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set tabstop, softtabstop and shiftwidth to the same value
command! -nargs=1 Rename let tpname = expand('%:t') | saveas <args> | edit <args> | call delete(expand(tpname))
command! -nargs=* Stab call Stab()
"普通模式和可视模式下&都代表着重复上一次搜索操作,同时保持上一次的搜索域
nnoremap & :&&<CR>
xnoremap & :&&<CR>
" 可视模式下,用 * 和 # 搜索选中文本
xnoremap * :<C-u>call <SID>VSetSearch()<CR>/<C-r>=@/<CR><CR>
xnoremap # :<C-u>call <SID>VSetSearch()<CR>?<C-r>=@/<CR><CR>
function! s:VSetSearch()
let temp = @s
norm! gv"sy
let @/ = '\V' . substitute(escape(@s, '/\'), '\n', '\\n', 'g')
let @s = temp
endfunction
function! Stab()
"设置缩进
let l:tabstop = 1 * input('set tabstop = softtabstop = shiftwidth = ')
if l:tabstop > 0
let &l:sts = l:tabstop
let &l:ts = l:tabstop
let &l:sw = l:tabstop
endif
call SummarizeTabs()
endfunction
function! SummarizeTabs()
"查看当前的缩进情况
try
echohl ModeMsg
echon 'tabstop='.&l:ts
echon ' shiftwidth='.&l:sw
echon ' softtabstop='.&l:sts
if &l:et
echon ' expandtab'
else
echon ' noexpandtab'
endif
finally
echohl None
endtry
endfunction
function! GuiTabLabel()
let label = ''
let bufnrlist = tabpagebuflist(v:lnum)
" Add '+' if one of the buffers in the tab page is modified
for bufnr in bufnrlist
if getbufvar(bufnr, "&modified")
let label = '+'
break
endif
endfor
" Append the tab number
let label .= v:lnum.': '
" Append the buffer name
let name = bufname(bufnrlist[tabpagewinnr(v:lnum) - 1])
if name == ''
" give a name to no-name documents
if &buftype=='quickfix'
let name = '[Quickfix List]'
else
let name = '[No Name]'
endif
else
" get only the file name
let name = fnamemodify(name,":t")
endif
let label .= name
" Append the number of windows in the tab page
let wincount = tabpagewinnr(v:lnum, '$')
return label . ' [' . wincount . ']'
endfunction
function! SetTabLabel()
set guitablabel=%{GuiTabLabel()}
endfunction
" http://vimdoc.sourceforge.net/htmldoc/gui.html
"echom "May The FORCE be with U!"
if exists('+showtabline')
function! MyTabLine()
let s = ''
let t = tabpagenr()
let i = 1
while i <= tabpagenr('$')
let buflist = tabpagebuflist(i)
let winnr = tabpagewinnr(i)
let s .= '%' . i . 'T'
let s .= (i == t ? '%1*' : '%2*')
let s .= ' '
let s .= i . ':'
let s .= ' %*'
let s .= (i == t ? '%#TabLineSel#' : '%#TabLine#')
let file = bufname(buflist[winnr - 1])
let file = fnamemodify(file, ':p:t')
if file == ''
let file = '[No Name]'
endif
let s .= file
let i = i + 1
endwhile
let s .= '%T%#TabLineFill#%='
let s .= (tabpagenr('$') > 1 ? '%999XX' : 'X')
return s
endfunction
set stal=2
set tabline=%!MyTabLine()
endif
"http://vim.wikia.com/wiki/Show_tab_number_in_your_tab_line
" set up tab tooltips with every buffer name
function! GuiTabToolTip()
let tip = ''
let bufnrlist = tabpagebuflist(v:lnum)
for bufnr in bufnrlist
" separate buffer entries
if tip != ''
let tip .= " \n "
endif
" Add name of buffer
let name = bufname(bufnr)
" add modified/modifiable flags
if getbufvar(bufnr, "&modified")
let tip .= ' [+]'
endif
endfor
return tip
endfunction
set guitabtooltip=%{GuiTabToolTip()}
" url:http://vimcasts.org/episodes/tidying-whitespace/
function! Preserve(command)
" Preparation: save last search, and cursor position.
let _s=@/
let l = line('.')
let c = col('.')
" Do the business:
execute a:command
" Clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction
nnoremap _$ :call Preserve("%s/\\s\\+$//e")<CR> "clean space in the end of line
nnoremap _= :call Preserve("normal gg=G")<CR>
"Allow to toggle background
function! ToggleBG()
let s:tbg = &background
" Inversion
if s:tbg == 'light'
set background=dark
else
set background=light
endif
endfunction
" set background is dark at the startup
set background=dark
noremap <leader>bg :call ToggleBG()<CR>
"CompileConfig
map <leader>r :call CompileRun()<CR>
"TODO: seperate compile and run
func! CompileRun()
exec "w"
if &filetype == 'c'
exec "g++ % -o %<"
elseif &filetype == 'cpp'
exec "g++ % -o %<"
exec "!time ./%<"
elseif &filetype == 'java'
exec "!clear"
exec "!javac %"
exec "!time java %<"
elseif &filetype == 'sh'
exec "!clear"
exec "!time bash %"
elseif &filetype == 'python'
exec "!python3 %"
elseif &filetype == 'html'
exec "!open -a Safari % &"
elseif &filetype == 'go'
exec "!clear"
exec "!go build %<"
exec "!time go run %"
elseif &filetype == 'markdown'
exec "!clear"
exec "!open -a Marked %"
elseif &filetype == 'tex'
exec "silent! VimtexCompile &"
endif
endfunc
augroup quickfix
autocmd!
autocmd QuickFixCmdPost make nested copen
augroup END
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" FileType Conifgure "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
autocmd! BufNewFile,BufRead *.vs,*.fs set filetype=glsl
autocmd! BufNewFile,BufRead *.swift set filetype=swift
autocmd! BufNewFile,BufRead *.markdown *.md set filetype=markdown
autocmd! BufNewFile,BufRead,BufReadPost *.snippets set filetype=snippets
autocmd! BufNewFile,BufRead *.json set filetype=json
autocmd! BufNewFile,BufRead *.ts set filetype=typescript
autocmd! BufNewFile,BufRead *.vm *.xtpl *.ejs set filetype=html
autocmd! BufNewFile,BufRead *.html.twig set filetype=html.twig
autocmd! BufNewFile,BufRead *.conf set filetype=config
autocmd! BufRead,BufNewFile *.scss set filetype=scss.css
autocmd! BufNewFile,BufRead *.coffee set filetype=coffee
autocmd! BufNewFile,BufRead *.rss *.atom setfiletype xml
autocmd! BufNewFile,BufRead *.vm set ft=velocity
autocmd! BufNewFile,BufRead *.mako set ft=mako
autocmd! BufNewFile,BufRead *.tex set filetype=tex
autocmd! BufNewFile,BufRead *.bat
\ if getline(1) =~ '--\*-Perl-\*--' | setf perl | endif
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Themes "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" should be placed before AutoCMD, or some color configure will not avaliable
" colorscheme Tomorrow-Night
" colorscheme PaperColor
" colorscheme hybrid_material
" colorscheme mayansmoke
" colorscheme anderson
" colorscheme wombat256
" colorscheme space-vim-dark
colorscheme gruvbox
" colorscheme vividchalk
" colorscheme night-owl
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" AutoCMD "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Return to last edit position when opening files (You want this!)
autocmd BufReadPost *
\ if &filetype != "gitcommit" && line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" autocmd! BufWritePost .vimrc source ~/.vimrc " source vimrc immediately
autocmd! FileType gitcommit autocmd! BufEnter COMMIT_EDITMSG
\ call setpos('.', [0, 1, 1, 0]) " set it to the first line when editing a git commit message
autocmd! FileType css set omnifunc=csscomplete#CompleteCSS
autocmd Filetype *
\if &omnifunc == "" |
\setlocal omnifunc=syntaxcomplete#Complete |
\endif
autocmd! FileType python syn keyword pythonDecorator True None False self
autocmd FocusGained, BufEnter * :silent! !
autocmd VimEnter * :call SetTabLabel()
autocmd WinEnter call SetTabLabel()
autocmd BufEnter call SetTabLabel()
"
"https://superuser.com/questions/195022/vim-how-to-synchronize-nerdtree-with-current-opened-tab-file-path
if expand("%:p")
autocmd BufEnter * lcd %:p:h
endif
"http://inlehmansterms.net/2014/09/04/sane-vim-working-directories/
"http://vim.wikia.com/wiki/Set_working_directory_to_the_current_file
autocmd BufEnter * silent! lcd %:p:h
autocmd BufEnter * if expand("%:p:h") !~ '^/tmp' | silent! lcd %:p:h | endif
let s:default_path = escape(&path, '\ ') " store default value of 'path'
" Always add the current file's directory to the path and tags list if not
" already there. Add it to the beginning to speed up searches.
autocmd BufRead *
\ let s:tempPath=escape(escape(expand("%:p:h"), ' '), '\ ') |
\ exec "set path-=".s:tempPath |
\ exec "set path-=".s:default_path |
\ exec "set path^=".s:tempPath |
\ exec "set path^=".s:default_path
" Automatically open and close the popup menu / preview window
autocmd CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif
" gnuplot syntax highlighting
autocmd BufNewFile,BufRead *.plt,.gnuplot setf gnuplot
autocmd ColorScheme * highlight ExtraWhitespace ctermbg=red guibg=red
autocmd FileType ruby set dictionary+=~/.vim/dict/ruby.dict
autocmd FileType javascript set dictionary+=$HOME/.vim/dict/node.dict
" 按照PEP8标准来配置vim
autocmd BufNewFile,BufRead *.py,*.cpp,*.java set tabstop=4 |set softtabstop=4|
\ set shiftwidth=4|set textwidth=79|set expandtab|set autoindent
\ |set fileformat=unix
" set auto wrap for tex
autocmd BufNewFile,BufRead *.tex set textwidth=79 |set fileformat=unix