-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.vim
More file actions
1470 lines (1340 loc) · 48.5 KB
/
init.vim
File metadata and controls
1470 lines (1340 loc) · 48.5 KB
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
set nocompatible
" Specify a directory for plugins
" - For Neovim: ~/.local/share/nvim/plugged
" - Avoid using standard Vim directory names like 'plugin'
call plug#begin('~/.local/share/nvim/plugged')
Plug 'https://github.com/majutsushi/tagbar.git'
" Plug 'liuchengxu/vista.vim'
Plug 'preservim/nerdtree'
Plug 'Xuyuanp/nerdtree-git-plugin'
" Plug 'neoclide/coc.nvim', {'branch': 'release'}
" Plug 'pappasam/coc-jedi', { 'do': 'yarn install --frozen-lockfile && yarn build' }
Plug 'https://github.com/vim-scripts/ScrollColors.git'
Plug 'https://github.com/tpope/vim-fugitive.git'
Plug 'mhartington/formatter.nvim'
Plug 'williamboman/nvim-lsp-installer'
Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-vsnip'
Plug 'tzachar/cmp-tabnine', { 'do': './install.sh' } " tooooooo slow.
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} " We recommend updating the parsers on update
Plug 'git@github.com:Mizux/vim-colorschemes.git'
" Plug 'romgrk/nvim-treesitter-context'
Plug 'lukas-reineke/indent-blankline.nvim'
Plug 'sheerun/vim-polyglot'
Plug 'OmniSharp/omnisharp-vim'
" Plug 'git@github.com:dense-analysis/ale.git'
Plug 'kkoomen/vim-doge', { 'do': { -> doge#install() } }
Plug 'Eric-Song-Nop/vim-glslx'
Plug 'mfussenegger/nvim-dap'
Plug 'leoluz/nvim-dap-go'
Plug 'theHamsta/nvim-dap-virtual-text'
" Plug 'rcarriga/nvim-dap-ui'
" Plug 'puremourning/vimspector'
" Track the engine.
Plug 'hrsh7th/vim-vsnip'
Plug 'hrsh7th/vim-vsnip-integ'
" Plug 'vim-airline/vim-airline'
" Plug 'vim-airline/vim-airline-themes'
" Plug 'git@github.com:lukas-reineke/indent-blankline.nvim.git' " 0.5
" Plug 'https://github.com/adelarsq/neoline.vim' " 0.5
" If you want to have icons in your statusline choose one of these
Plug 'kyazdani42/nvim-web-devicons'
" Plug 'ryanoasis/vim-devicons'
Plug 'git@github.com:yamatsum/nvim-nonicons.git'
Plug 'nvim-lua/plenary.nvim'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'HerringtonDarkholme/yats.vim'
" Plug 'mhartington/nvim-typescript', {'do': './install.sh'}
Plug 'mileszs/ack.vim'
Plug 'https://github.com/heavenshell/vim-pydocstring.git'
Plug 'norcalli/nvim-colorizer.lua'
Plug 'wakatime/vim-wakatime'
Plug 'frazrepo/vim-rainbow'
"""color scheme
Plug 'git@github.com:humanoid-colors/vim-humanoid-colorscheme.git'
" Plug 'https://github.com/lifepillar/vim-wwdc17-theme.git'
Plug 'https://github.com/arzg/vim-colors-xcode.git'
" Plug 'ayu-theme/ayu-vim'
Plug 'mhartington/oceanic-next'
Plug 'folke/lsp-colors.nvim'
Plug 'git@github.com:folke/tokyonight.nvim.git'
" with tree-sitter
Plug 'marko-cerovac/material.nvim'
Plug 'bluz71/vim-nightfly-guicolors'
""" mark down
Plug 'davidgranstrom/nvim-markdown-preview'
"""" neovim lua plugin
Plug 'mjlbach/neovim-ui'
Plug 'nvim-lua/plenary.nvim'
Plug 'sindrets/diffview.nvim'
" Plug 'kyazdani42/nvim-tree.lua'
" Plug 'TimUntersberger/neogit'
call plug#end()
set diffexpr=MyDiff()"{{{
function! MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
let eq = ''
if $VIMRUNTIME =~ ' '
if &sh =~ '\<cmd'
let cmd = '""' . $VIMRUNTIME . '\diff"'
let eq = '"'
else
let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
endif
else
let cmd = $VIMRUNTIME . '\diff'
endif
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction
"}}}
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
syntax on
set autoread
set cursorline ""hilight current line
if (has("termguicolors"))
let $NVIM_TUI_ENABLE_TRUE_COLOR=1
set termguicolors
endif
set nu
filetype on
filetype plugin indent on
filetype indent plugin on
set hlsearch
set foldmethod=marker
set tabstop=4
set shiftwidth=4
set softtabstop=4
set nowrap
set expandtab
set autoindent
set background=light
" let ayucolor="light" " for light version of theme
" let ayucolor="mirage" " for mirage version of theme
" let ayucolor="dark" " for dark version of theme
" colo ayu
" colo xcodewwdc
" colo pencil
" colo lucario
" colo slate
colo humanoid
" colo xcodedark
" colo flattened_light
" colo challenger_deep
" There are 5 different styles of material available:
" colo material
" darker
" lighter
" oceanic
" palenight
" deep ocean
""""" Set the desired style using:
let g:material_style = 'oceanic'
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"file encoding
set fileencodings=utf8,ucs-bom,gbk,cp936,gb18030
"set termencoding=utf-8,gbk,ucs-bom
set encoding=utf-8
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" format
" session"{{{
function! SaveSession()
let ch = confirm("save session ?", "&Yes\n&No", 1)
if ch == 1
exe ":wa!"
exe "mksession! .session.vim"
else
echo "save session cancle."
endif
endfunction
" set sessionoptions=buffers,curdir,resize,folds,tabpages,slash,resize,winpos,winsize
set sessionoptions=curdir,resize,folds,tabpages,slash,resize,winpos,winsize,terminal
nmap <F2> :call SaveSession()<CR>
function! LoadSession(confirmed)
let aconf = a:confirmed
if aconf != 1
let aconf = confirm("load last session ?", "&Yes\n&No", 1)
endif
if aconf == 1
exe ":so .session.vim"
else
echo "load seesion cancled."
endif
endfunction
nmap <F3> :call LoadSession(0)<CR>
"}}}
let g_my_runner2files = {}
function PromotSelectCmd(runner)
let bname = bufnr()
let opts = []
if has_key(g:g_my_runner2files, bname)
let opts = g:g_my_runner2files[bname]
end
let idx = len(opts)
if len(opts) > 0
let selects = []
let ti = 0
for tm in opts
call add(selects, ti . ".|" . tm)
let ti += 1
endfor
let idx = inputlist(selects + [ len(selects) . '.| <new cmd>'])
endif
let excmd = ""
if idx == len(opts)
let excmd = input(a:runner . ' :', expand('%'), 'file')
call insert(opts, excmd)
if len(opts) > 4
let didx = len(opts) - 1
call remove(opts, didx)
end
let g:g_my_runner2files[bname]=opts
else
let idx = idx - 1
let excmd = opts[idx]
let excmd = input('python3 debug:', len(excmd) > 0 ? excmd : expand('%'), 'file')
endif
return excmd
endfunction
function! DebugPython()
let bname = bufnr()
let exname = PromotSelectCmd('pdbr')
" eval("let g:g_my_runner2files." . bname . " = exname")
vs
let cmd = "terminal pdbr -c 'b " . expand('%') . ":" . line('.') . "' -c continue " . exname
" echo 'cmd:' cmd
exe cmd
endfunction
function! RunCmdForCurFile()
let bname = bufnr()
let ftype2runners = {
\ 'go': 'go',
\ 'python': 'python3',
\ 'sh': 'sh',
\}
let ft = &filetype
let runner = ''
if has_key(ftype2runners, ft)
let runner = ftype2runners[ft]
else
echo 'no runner for [' . ft . '] type is not supported yet!'
return
endif
let excmd = PromotSelectCmd(runner)
" eval("let :g_my_runner2files." . bname . " = exnames")
9sp
exe 'terminal ' . runner . ' ' . excmd
endfunction
" autocmd FileType python set makeprg=python3\ -c\ \"import\ py_compile,sys;\ sys.stderr=sys.stdout;\ py_compile.compile(r'%')\"
" autocmd FileType python set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
autocmd FileType python setlocal tabstop=4 shiftwidth=4 softtabstop=4 expandtab
autocmd FileType python nmap ¡ :call DebugPython()<CR>
nmap ™ :call RunCmdForCurFile()<CR>
function! Format_Python()
let filtePattern = [":%s/\\s*:\\s*/:/g", ":%s/(\\s*/(/g", ":%s/\\s*)/)/g", ":%s/[\\s*/[/g", ":%s/\\s*]/]/g", ":%s/{\\s*/{/g", ":%s/\\s*}/}/g", ":%s/\\s*$//g"]
call add(filtePattern, ":%s/\t/ /g")
for fp in filtePattern
try
exec fp
catch E486
endtry
endfor
endfunction
" autocmd FileType python nmap <leader>fm :call Format_Python()<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" comment line."
function! CommentLine()"{{{
let commtdict = {
\ 'lua': '--',
\ 'toml': '#',
\ 'yaml': '#',
\ 'yaml.docker': '#',
\ 'java': '//',
\ 'go': '//',
\ 'c': '//',
\ 'cpp': '//',
\ 'h': '//',
\ 'cs': '//',
\ 'typescript': '//',
\ 'js': '//',
\ 'javascript': '//',
\ 'omnijs': '//',
\ 'python': '#',
\ 'vim': '"',
\ 'shader': '//',
\ 'glsl': '//',
\ 'sh': '#',
\ 'objc': '//',
\}
let ft = &filetype
let commtchar = ''
if has_key(commtdict, ft)
let commtchar = commtdict[ft]
else
echo 'comment [' . ft . '] type is not supported yet!'
return
endif
let commentPattern = '^\s*\t*' . commtchar . '\s*'
let line = getline('.')
if strlen(substitute(line, '[\s\t]', '', '')) < 1
return
endif
" comment added.
if line =~ commentPattern
let idx = stridx(line, commtchar, 0)
let lineIndent = strpart(line, 0, idx)
let content = strpart(line, idx + strlen(commtchar), strlen(line) - strlen(commtchar) - idx)
let content = substitute(content, '^\s*\t*', '', '')
call setline('.', lineIndent . content)
" uncomment.
else
let noindentLine = substitute(line, '^\s*\t*', '', '')
let idx = stridx(line, noindentLine)
let newline = strpart(line, 0, idx) . commtchar . ' ' . noindentLine
call setline('.', newline)
endif
endfunction"}}}
noremap tm :call CommentLine()<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" replace current word.
vmap tr "xy:exe "%s/" . @x . "/" . input("replace all [" . @x . "] by: ") . "/cg"<CR>
vmap tr$ "xy:exe ",$s/" . @x . "/" . input("replace to end [" . @x . "] by: ") . "/cg"<CR>
map tu zz:e!<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" find word in directories."{{{
"
function EscapeLitters(win)
let kw = a:win
let toescaps = [".", "/", "'", "[", "]"]
for tk in toescaps
let tidx = stridx(kw, tk)
if tidx >= 0
let kw = strpart(kw, 0, tidx) . '\' . strpart(kw, tidx, len(kw))
endif
endfor
return kw
endfunction
let g:ackprg = 'ag --nogroup --nocolor --column'
let g_my_search_replace_all = 0
let g_my_search_keyword = ''
function! SearchWordGlobal(keyword)
let kw = a:keyword
if len(kw) < 1
normal! gv"xy
let kw = @x
endif
"""" escap
let kw = EscapeLitters(kw)
let hint = "find [" . kw . "] by extension:"
let extname = input(hint, expand("%:e"))
if len(extname) == 0 || extname == "*"
let g:ackprg = 'ag -a --nogroup --nocolor --column '
else
let g:ackprg = 'ag --nogroup --nocolor --column --' . extname
endif
let cmdstr = "Ack '" . kw . "'"
if isdirectory('Assets')
let cmdstr = cmdstr . " ./Assets"
endif
exe cmdstr
let g:g_my_search_keyword = kw
" let wid = win_getid()
" win_gotoid(wid)
let qflst = getqflist()
if len(qflst) > 0
copen
let g:g_my_search_replace_all = len(qflst)
endif
" echo 'search: [' . kw . "] matches " . len(qflst)
endfunction
nmap <silent> Tf :call SearchWordGlobal(expand("<cword>"))<CR>
vmap <silent> Tf :call SearchWordGlobal('')<CR>
function! SearchWordInCurrentFile(kw)
let keyword = EscapeLitters(a:kw)
if len(keyword) < 1
normal! gv"xy
let keyword = @x
endif
exe "vimgrep /" . keyword . '/ %'
" echo "CAg " . kw . ' ./**/*.' . expand("%:e")
" let g:g_my_search_keyword = kw
" let wid = win_getid()
" win_gotoid(wid)
" let qflst = getqflist()
" if len(qflst) > 0
" copen
" let g:g_my_search_replace_all = len(qflst)
" endif
" echo 'search: [' . kw . "] matches " . len(qflst)
endfunction
nmap <silent> tf :call SearchWordInCurrentFile(expand("<cword>"))<CR>
vmap <silent> tf :call SearchWordInCurrentFile('')<CR>
" replace words in directories
function! ReplaceWordGlobal( noConfirm, matchWord)
let qflst = getqflist()
let g:g_my_search_replace_all = len(qflst) > 0
if( g:g_my_search_replace_all == 0)
return
endif
call inputsave()
if(a:matchWord == 0 )
let newkw = input("Replace [" . g:g_my_search_keyword . "]by ", '')
let replaceCmd = ":%s/" . g:g_my_search_keyword . "/" . newkw
else
let replaceCmd = ":%s/\\<" . g:g_my_search_keyword . "\\>/" . newkw
let newkw = input("Replace Word[" . g:g_my_search_keyword . "]by ", '')
endif
call inputrestore()
if a:noConfirm == 0
let replaceCmd= replaceCmd . "/g"
else
let replaceCmd= replaceCmd . "/gc"
endif
call inputrestore()
let bufnums = []
for qf in getqflist()
if index(bufnums, qf.bufnr) > -1
continue
endif
call add( bufnums, qf.bufnr )
endfor
echo 'fuck' bufnums
for bufnum in bufnums
exe ":b" . bufnum
exe replaceCmd
endfor
endfunction
nmap <silent> zr :call ReplaceWordGlobal(1, 0)<CR>
nmap <silent> zw :call ReplaceWordGlobal(1, 1)<CR>
"}}}
" find word in correspond file
"function! SearchWordInCorrespondFile()
"let cw ="/" . input("corresponding search: ", expand("<cword>")) . "/g"
"let distPath = "" . expand("%<.cpp") . " " expand("%<.h") . " " . expand("%<.c")
"exe "vimgrep " . cw . " " . distPath . ""
"exe ":cw"
"endfunction
"autocmd FileType c,cpp nmap tof :call SearchWordInCorrespondFile()<CR>
"
" swap word
function SplitAndSwap()
normal! gv"xy
let keyword = @x
let istailc = 0
if keyword[ len(keyword) -1] == ';'
let istailc = 1
endif
let words = split(keyword, '[:=;]')
" echo words
let outs = words[1] . " " . words[0]
if istailc
let outs = outs . ";"
endif
for tw in words[2:]
let outs = outs . tw
endfor
" echo "rslt: " . outs
call setline(".", substitute(getline("."), keyword, outs, ""))
return outs
endfunction
vmap <silent> ts: call SplitAndSwap()<CR>
function! ConvertTs2cs()
let cmds = [
\':%s/console.error(/Log.Error(/g',
\':%s/console.log(/Log.Info(/g',
\':%s/(\s*`/($"/gc',
\':%s/^\s*\t*`/$"/gc',
\':%s/`/"/g',
\':%s/${/{/g',
\':%s/\<let\>/var/g',
\':%s/\.length/.Length/g',
\':%s/\.clear/.Clear/g',
\':%s/\<number\>/float/g',
\':%s/\.push/.Add/g',
\':%s/^\s*export\s\+function\s\+/public void /g',
\':%s/^\s*export\s\+namesapce/public/g',
\':%s/^\s*export\s\+/public/g',
\':%s/math.floor/Mathf.Floor/g',
\':%s/math.abs/Mathf.Abs/g',
\':%s/math.random()/UnityEngine.Random.value/g',
\':%s/Map</Dictionary</g',
\':%s/\<toString\>/ToString/g',
\]
" echo cmds
for tc in cmds
try
echo "regx:" . tc
exe tc
catch E486
" echo "no need fix"
endtry
endfor
return
endfunction
" hex model
nnoremap <silent> hex :%!xxd<CR>
nnoremap <silent> nhex :%!xxd -r<CR>
" quick fixs
map <silent> tcn :cn<CR>
map <silent> tcp :cp<CR>
map <silent> tco :copen<CR>
map <silent> tcl :cclose<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" for folding {{{
set foldcolumn=2
"set foldmethod=indent
set foldmethod=marker
set foldmarker={{{,}}}
function! CreateFoldByRegion(regionSign)
let startLineNum = line('.')
while stridx(getline(startLineNum), a:regionSign) < 0
let startLineNum = startLineNum + 1
if startLineNum == line('$')
echo "reach end of file, can not create folding!"
return
endif
endwhile
exe "normal ^f" . a:regionSign
if startLineNum == line('.') "is current line.
exe "normal V%zf"
else
let moveDown = startLineNum - line('.')
exe "normal V" . moveDown . "j%zf"
endif
endfunction
autocmd FileType c,cpp,h,cs nmap <silent> tzf :call CreateFoldByRegion('{')<CR>
nmap <silent> tza^ :call setline(v:lnum, getline(v:lnum) . "\t\t//{{{")<CR>
nmap <silent> tza$ :call setline(v:lnum, getline(v:lnum) . "\t\t//}}}")<CR>
""" }}}
" add file discription."{{{
function! AddDescription()
echo ' in file description'
let lineCnt = len(getbufline(bufname("%"), 0, "$"))
if lineCnt > 1
return 0
endif
let commtdict = {
\ 'c': '//',
\ 'ts': '//',
\ 'cpp': '//',
\ 'h': '//',
\ 'cs': '//',
\ 'python': '#',
\ 'vim': '"',
\ 'typescript': '//',
\}
let ft = &filetype
let commtchar = ''
if has_key(commtdict, ft)
let commtchar = '' . commtdict[ft]
else
echo ft . ' type is not supported yet!'
return
endif
let time = commtchar . " @" . strftime("%c")
let file = commtchar . ' ' . expand("%")
let author = commtchar . " created by yuhui."
let description = [file, commtchar, commtchar, author, time, '']
let exfn = expand('%:e')
if exfn == "h"
let macro = toupper(expand("%"))
let tmacro = "#ifndef " . strpart(macro, 0, strlen(macro)-2) . "_H"
""echo macro
call add(description, tmacro)
""echo description
let macro = "#define " . strpart(macro, 0, strlen(macro)-2) . "_H"
call add(description, macro)
call add(description, " ")
call add(description, "{")
call add(description, "}")
call add(description, "#endif")
elseif exfn == 'c' || exfn == 'cpp'
let isSrcFile = tolower(strpart(file, strlen(file) - 4, 4)) == '.cpp' ? 4 : tolower(strpart(file, strlen(file) - 2, 2)) == '.c' ? 2 : 0
if isSrcFile > 0
let theader = expand("%")
let theader = strpart(file, 1, strlen(file) - isSrcFile)
let theader = '#include "' . theader . 'h"'
call add(description, theader)
call add(description, '')
endif
elseif exfn == 'py'
call insert(description, "#!/usr/bin/python3", 0)
call insert(description, "# -*- coding: utf-8 -*-", 1)
else
endif
let fail= append(0, description)
if fail
return 1
endif
endfunction
autocmd FileType typescript,c,cpp,h,cs,python exe "call AddDescription()"
"}}}
""""""""""""""""""""
" coc diagnostic status
function! StatusDiagnostic() abort
let info = get(b:, 'coc_diagnostic_info', {})
if empty(info) | return '' | endif
let msgs = []
if get(info, 'error', 0)
call add(msgs, 'E' . info['error'])
endif
if get(info, 'warning', 0)
call add(msgs, 'W' . info['warning'])
endif
return join(msgs, ' ') . ' ' . get(g:, 'coc_status', '')
endfunction
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" status line
if exists('g:gui_oni')
set mouse=a
" Turn off statusbar, because it is externalized
" set noshowmode
"set noruler
" set laststatus=0
" set noshowcmd
set laststatus=2
set statusline=%=%{"|"}%f\ %ybuf:%n%h%m%r%=%{tagbar#currenttag('【%s】','','f')}%=\ %r%P%{\"[\".(&fenc==\"\"?&enc:&fenc).((exists(\"+bomb\")\ &&\ &bomb)?\",B\":\"\").\"]\ \"}
else
" let g:airline#extensions#coc#enabled = 1
" let g:airline#extensions#ale#enabled = 1
set laststatus=2
set statusline=\|%-10f\ %y%=buf:%n%h%m%r
set statusline+=\|%<%{FugitiveHead()}\|
" set statusline+=%<%{'win:' . winnr()}
" set statusline+=%{SyntasticStatuslineFlag()}
" let g:airline_section_z = '%l/%L|B%n'
" set statusline+=%{StatusDiagnostic()}
set statusline+=%{(&fenc==\"\"?&enc:&fenc).((exists(\"+bomb\")\ &&\ &bomb)?\",B\":\"\").\"\|\"}
set statusline+=%k%(%l/%L%)\|%P
endif
""""""""""""""""""""""""""""""for NERDTree"{{{
" >> auto change current directory to current openning file.
nnoremap <silent> Tn :let curPath =expand("%:h:p")<Bar> exec "NERDTree " . (len(curPath)<1 ? "." : curPath)<CR>
" let g:nvim_tree_respect_buf_cwd = 1 "0 by default, will change cwd of nvim-tree to that of new buffer's when opening nvim-tree.
" nnoremap <silent> Tn :NvimTreeToggle<CR>
"}}}
""""""""""""""""""""""""""""""""""""""""""" Vista"{{{
" How each level is indented and what to prepend.
" This could make the display more compact or more spacious.
" e.g., more compact: ["▸ ", ""]
" Note: this option only works for the kind renderer, not the tree renderer.
let g:vista_icon_indent = ["╰─▸ ", "├─▸ "]
" Executive used when opening vista sidebar without specifying it.
" See all the avaliable executives via `:echo g:vista#executives`.
let g:vista_default_executive = 'ctags'
" Set the executive for some filetypes explicitly. Use the explicit executive
" instead of the default one for these filetypes when using `:Vista` without
" specifying the executive.
let g:vista_executive_for = {
\ 'cpp': 'vim_lsp',
\ 'php': 'vim_lsp',
\ 'python': 'vim_lsp',
\ }
" Declare the command including the executable and options used to generate ctags output
" for some certain filetypes.The file path will be appened to your custom command.
" For example:
let g:vista_ctags_cmd = {
\ 'haskell': 'hasktags -x -o - -c',
\ }
" To enable fzf's preview window set g:vista_fzf_preview.
" The elements of g:vista_fzf_preview will be passed as arguments to fzf#vim#with_preview()
" For example:
let g:vista_fzf_preview = ['right:50%']
" Ensure you have installed some decent font to show these pretty symbols, then you can enable icon for the kind.
let g:vista#renderer#enable_icon = 1
" The default icons can't be suitable for all the filetypes, you can extend it as you wish.
let g:vista#renderer#icons = {
\ "function": "\uf794",
\ "variable": "\uf71b",
\ }
nnoremap <silent> Tv :Vista!! <CR>
"}}}
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"open current file's header or cpp. toc : t mode o open c corespond."{{{
function! OpenFile2Cword(cfname)
if filereadable(a:cfname)
let kw = expand("<cword>")
exe "vs " . a:cfname
let searchcmd = "vimgrep /" . kw . "/ %"
exe searchcmd
exe "normal zz"
else
let ch = confirm("Do not exists, create file ?", "&Yes\n&No", 1)
if ch = 1
exe "vs " . a:cfname
endif
endif
endfunction
function! OpenCorrespondFile()
let fname=expand("%")
let idot=strridx(fname, ".")
if idot >0
let exh =tolower(strpart(fname, idot+1, 1))
let mname = strpart(fname, 0, idot)
if exh == "c"
let cfname = mname . ".h"
elseif exh == "cpp"
let cfname = mname . ".h"
elseif exh == "h"
let cfname = mname . ".c"
if filereadable(cfname)
let cfname = mname . ".c"
else
let cfname = mname . ".cpp"
endif
endif
call OpenFile2Cword(cfname)
else
echo fname . "is not a valid source file"
endif
endfunction
autocmd FileType c,cpp,inl nnoremap <silent> toc : call OpenCorrespondFile()<CR>
"}}}
""""""""""""""""""""""""""""""""""""""
"diff
set diffopt+=iwhite
set diffexpr=""
"map tdf :let tg=input("compare to", expand("%<"),
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" synatx
"au FileType frag,vert,fp,vp,glsl,vsh,fsh setf glsl
syntax enable
syntax sync minlines=256
au BufNewFile,BufRead *.frag,*.vert,*.fp,*.vp,*.glsl setf glsl
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" color scroll
nmap <silent> <leader>cs :SCROLL<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" airline
" AirlineTheme oceanicnextlight
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" higroup
highlight mhl1 ctermfg=red guifg=red ctermbg=gray
highlight mhl2 ctermfg=green guifg=green ctermbg=gray
highlight mhl3 ctermfg=blue guifg=blue ctermbg=gray
highlight CocErrorSign ctermbg=red ctermfg=white guifg=blue
let _multiHiNames = ["mhl1", "mhl2", "mhl3"]
let _multiHiKws = {}
function! ExtralHilight(kw)
if has_key(g:_multiHiKws, a:kw)
let hmark = g:_multiHiKws[a:kw]
call matchdelete(hmark)
call remove(g:_multiHiKws, a:kw)
echo "remove hilight [" . a:kw . "] remain " . len(g:_multiHiKws)
else
let hidx = len(g:_multiHiKws)
if hidx >= len(g:_multiHiNames)
let hidx = len(g:_multiHiNames) - 1
endif
let hname = g:_multiHiNames[hidx]
let m = matchadd(hname, a:kw)
let g:_multiHiKws[a:kw] = m
echo "add hilight [" . a:kw . "] " . len(g:_multiHiKws)
endif
endfunction
nmap <leader>h :call ExtralHilight(expand("<cword>"))<CR>
vmap <leader>h "xy:call ExtralHilight(@x)<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" terminal
function! OpenTerminalSplit(cmd)
exe a:cmd
" if isdirectory("./venv")
" exe ":terminal source ./venv/bin/activate"
" else
exe ":terminal"
setlocal nowrap
endfunction
nmap zm :call OpenTerminalSplit('20split')<CR>
nmap zvm :call OpenTerminalSplit('vs')<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" fzf
nnoremap <C-p> :Files<CR>
nnoremap <C-f> :Ag<CR>
nnoremap <C-b> :Buffers<CR>
autocmd! FileType fzf
autocmd FileType fzf set laststatus=0 noshowmode noruler
\| autocmd BufLeave <buffer> set laststatus=2 showmode ruler
" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "
" vim indent
let g:indent_guides_enable_on_vim_startup = 1
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" " omnisharp
" let g:OmniSharp_server_install='/Users/yuhui/work/tool/omnisharp-osx/'
" let g:OmniSharp_server_path='/Users/yuhui/work/tool/omnisharp-osx/omnisharp/OmniSharp.exe'
" let g:OmniSharp_server_display_loading = 1
" let g:OmniSharp_server_use_mono = 1
" let g:OmniSharp_server_stdio = 1
" let g:OmniSharp_selector_ui = 'fzf'
" let g:OmniSharp_start_server = 1
" let g:OmniSharp_selector_findusages = 'fzf'
" let g:OmniSharp_popup = 1
" " Update semantic highlighting after all text changes
" let g:OmniSharp_highlight_types = 3
" " Update semantic highlighting on BufEnter and InsertLeave
" let g:OmniSharp_highlight_types = 2
" autocmd CursorHold *.cs OmniSharpTypeLookup
" autocmd FileType cs nmap <silent> <buffer> gd <Plug>(omnisharp_go_to_definition)
" autocmd FileType cs nmap <silent> <buffer> Fu <Plug>(omnisharp_find_usages)
" autocmd FileType cs nmap <silent> <buffer> Ft <Plug>(omnisharp_find_type)
" autocmd FileType cs nmap <silent> <buffer> Fs <Plug>(omnisharp_find_symbol)
" autocmd FileType cs nmap <silent> <buffer> <leader><space> <Plug>(omnisharp_code_actions)
" autocmd FileType cs nmap <silent> <buffer> Fx <Plug>(omnisharp_fix_usings)
" autocmd FileType cs nmap <silent> <buffer> Fk <Plug>(omnisharp_documentation)
" autocmd FileType cs nmap <silent> <buffer> Fm :OmniSharpCodeFormat<CR>
" autocmd FileType cs nmap <silent> <buffer> Fr <Plug>(omnisharp_rename)
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" ALE
" let g:ale_linters = { 'cs': ['OmniSharp'] }
" call ale#linter#Define('cs', {
" \ 'name': 'omnisharp',
" \ 'lsp': 'stdio',
" \ 'executable': '/Users/yuhui/work/tool/omnisharp-osx/run',
" \ 'command': '%e run',
" \ 'project_root': '.',
" \})
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" function! NearestMethodOrFunction() abort
" return get(b:, 'vista_nearest_method_or_function', '')
" endfunction
" set statusline+=%{NearestMethodOrFunction()}|
" By default vista.vim never run if you don't call it explicitly.
" "
" " If you want to show the nearest function in your statusline
" automatically,
" " you can add the following line to your vimrc
" let g:vista#renderer#enable_icon = 1
" autocmd VimEnter * call vista#RunForNearestMethodOrFunction()
" vmap t= <Plug>(coc-format-selected)
" nmap t= <Plug>(coc-format-selected)
" devicons
let g:webdevicons_enable_nerdtree = 1
" let g:webdevicons_enable_airline_tabline = 0
" let g:webdevicons_enable_airline_statusline = 0
let g:webdevicons_enable_ctrlp = 0
""""""""""""""""""""
" doge
"
let g:doge_enable_mappings = 1
let g:doge_mapping_comment_jump_forward = 1
let g:doge_mapping_comment_jump_backward = 1
""""""""""
" snippet
let g:vsnip_snippet_dir = expand('~/work/yuhuiVimConf/vsnips')
" NOTE: You can use other key to expand snippet.
" Expand
imap <expr> <C-j> vsnip#expandable() ? '<Plug>(vsnip-expand)' : '<C-j>'
smap <expr> <C-j> vsnip#expandable() ? '<Plug>(vsnip-expand)' : '<C-j>'
" Expand or jump
imap <expr> <C-l> vsnip#available(1) ? '<Plug>(vsnip-expand-or-jump)' : '<C-l>'
smap <expr> <C-l> vsnip#available(1) ? '<Plug>(vsnip-expand-or-jump)' : '<C-l>'
" Jump forward or backward
imap <expr> <Tab> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>'
smap <expr> <Tab> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>'
imap <expr> <S-Tab> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<S-Tab>'
smap <expr> <S-Tab> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<S-Tab>'
" Select or cut text to use as $TM_SELECTED_TEXT in the next snippet.
" See https://github.com/hrsh7th/vim-vsnip/pull/50
nmap s <Plug>(vsnip-select-text)
xmap s <Plug>(vsnip-select-text)
nmap S <Plug>(vsnip-cut-text)
xmap S <Plug>(vsnip-cut-text)
"""""""""""""""""""""
" colorizer.lua
lua require'colorizer'.setup()
""""""""""""""""""""
" vimspector
" let g:vimspector_base_dir=expand( '$HOME/.config/nvim/vimspector-config' )
" let g:vimspector_enable_mappings = 'HUMAN'
" nmap <leader>vl :call vimspector#Launch()<CR>
" nmap <leader>vr :VimspectorReset<CR>
" nmap <leader>ve :VimspectorEval
" nmap <leader>vw :VimspectorWatch
" nmap <leader>vo :VimspectorShowOutput
" nmap <leader>vi <Plug>VimspectorBalloonEval
" xmap <leader>vi <Plug>VimspectorBalloonEval
" let g:vimspector_install_gadgets = [ 'debugpy', 'vscode-go', 'CodeLLDB', 'vscode-node-debug2' ]
"" launch debug alt+t
" nmap † <Plug>VimspectorContinue
"" toggle breakpoint alt+b
" nmap ∫ <Plug>VimspectorToggleBreakpoint
"" step into alt+i
" nmap ˆ <Plug>VimspectorStepInto
"" step out alt+o
" nmap ø <Plug>VimspectorStepOut
"" step over alt+n
" nmap ˜ <Plug>VimspectorStepOver
"" up frame | Move up a frame in the current call stack alt+k | 'vimspector#UpFrame()' |
" nmap ˚ <Plug>VimspectorUpFrame
"" down frame | Move down a frame in the current call stack alt+∆ | 'vimspector#DownFrame()' |" down frame
" nmap ∆ <Plug>VimspectorDownFrame
""""""""""""""""""""
" clear cocos temp files
function! ClearCreatorTemps()
let cmd = "terminal ls; echo '-------deleted----------'; rm -rf ./local ./temp ./library;ls"
" echo 'cmd:' cmd
exe cmd
endfunction
set spelllang=en,cjk
function! SetupReHost()
if writefile([v:servername], '/Users/yuhui/.config/nvim/nvimserver')
echomsg 'nvim 服务器名称写出失败'
endif
endfunction
command SetUnitEditor call SetupReHost()
function! OpenAndroidLog()
exec "vert new"
exec "terminal adb logcat '*:S' Unity -v color | tee ~/Downloads/adblog.txt"
" exec 'read ~/Downloads/adblog.txt'
" setlocal buftype=nowrite