-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
1476 lines (1232 loc) · 50.1 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
" author: yantze
" $VIMHOME/vimrc.bundles " the package location
let g:color_dark = 1
" let g:no_compile_plugin = 1
" let g:no_vimrc_bundles = 1
" General {
" Enviroment {
" Basic
let mapleader=","
" 在之前用 <leader> 会使用默认的'\'
map ; :
" 共享系统粘贴板
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
" Platform Check
silent function! OSX()
return system('uname')=~'Darwin'
endfunction
silent function! LINUX()
return has('unix') && !has('macunix') && !has('win32unix')
endfunction
silent function! WINDOWS()
return (has('win16') || has('win32') || has('win64'))
endfunction
" 统一变量
if WINDOWS()
let $VIMHOME = $HOME."\\vimfiles" " C:\Users\User\vimfiles
let $VIMRC = $MYVIMRC
" set runtimepath=$HOME.'\.vim',$VIM.'\vimfiles',$VIMRUNTIME
else
let $VIMHOME = $HOME."/.vim"
let $VIMRC = $MYVIMRC
" set shell=/bin/sh
endif
" Package Manager
" 安装插件 :PlugInstall
if !exists("g:no_vimrc_bundles") && !empty(glob("$VIMHOME/vimrc.bundles"))
source $VIMHOME/vimrc.bundles
endif
" Adapte with putty because of putty only support the 7 character
" if $TERM == 'screen'
" http://vim.wikia.com/wiki/Get_Alt_key_to_work_in_terminal
" set <m-j>=j
" set <m-h>=h
" set <m-k>=k
" set <m-l>=l
"
" https://groups.google.com/forum/#!topic/vim_use/uKOmY-mHo_k
" 导致 ESC 延迟反应
" below set <esc> wait the next key millionstime
" set timeout timeoutlen=3000 ttimeoutlen=100
" 这个让 alt work in putty 的方法影响了其它平台的使用,禁用
" endif
" the ^[ is an Esc char that comes before the 'a'
" In most default configs, ^[a may be typed by pressing first <C-v>, then <M-a>
" http://vim.1045645.n5.nabble.com/Mapping-meta-key-within-tmux-td5716437.html
" Fix screen's key bindings.
" if &term == "screen"
" " These work from my HP keyboard in PuTTY on Windows XP.
" map <Esc>[D <S-Left>
" map <Esc>[C <S-Right>
" map <Esc>[11~ <F1>
" map <Esc>[12~ <F2>
" map <Esc>[13~ <F3>
" map <Esc>[14~ <F4>
" map <Esc>[15~ <F5>
" map <Esc>[16~ <F6>
" map <Esc>[17~ <F7>
" map <Esc>[18~ <F8>
" map <Esc>[19~ <F9>
" map <Esc>[21~ <F10
" map <Esc>[23~ <F11>
" map <Esc>[24~ <F12>
" endif
" if &term=="xterm"
" set t_Co=8
" set t_Sb=[4%dm
" set t_Sf=[3%dm
" endif
" }
" Functions {
" there func is for internal function invoal
" not relate the other plugin
func! CopyToCloud()
exec ":w !tee | xcopy"
" https://github.com/yantze/dotfiles/blob/master/usrbin/xcopy
endfunc
func! CopySelectedToCloud()
exec ":'<,'>:w !tee | xcopy"
endfunc
func! RunSelected()
exec ":s/\%V\(.*\)/{{__ "\1"}}/"
endfunc
func! PasteFromCloud()
endfunc
func! s:get_visual_selection()
" https://stackoverflow.com/questions/1533565/how-to-get-visually-selected-text-in-vimscript
let [line_start, column_start] = getpos("'<")[1:2]
let [line_end, column_end] = getpos("'>")[1:2]
let lines = getline(line_start, line_end)
if len(lines) == 0
return ''
endif
let lines[-1] = lines[-1][: column_end - (&selection == 'inclusive' ? 1 : 2)]
let lines[0] = lines[0][column_start - 1:]
return join(lines, "\n")
endfunc
func! RemoveTabs()
if &shiftwidth == 2
exec "%s/ / /g"
elseif &shiftwidth == 4
exec "%s/ / /g"
elseif &shiftwidth == 6
exec "%s/ / /g"
elseif &shiftwidth == 8
exec "%s/ / /g"
else
exec "%s/ / /g"
end
endfunc
func! RemoveQuotas()
silent! exec "%s/[“”]/\"/g"
silent! exec "%s/[‘’]/\'/g"
endfunc
func! Tab2()
set tabstop=2
set shiftwidth=2
set softtabstop=2
endfunc
func! Tab4()
" tab 键宽度为4空格
set tabstop=4
" 每一次缩进对应的空格数
set shiftwidth=4
" 按退格键可以一次删掉4个空格
set softtabstop=4
endfunc
" Diff current unsaved file
function! s:DiffWithSaved()
let filetype=&ft
diffthis
vnew | r # | normal! 1Gdd
diffthis
exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype
endfunction
" 编译并运行
func! Compile_Run_Code()
exec "w"
if &filetype == "c"
if WINDOWS()
exec !gcc -Wall -std=c11 -o %:r %:t && %:r.exe"
elseif OSX()
exec "!clang -Wall -std=c11 -o %:r %:t && ./%:r"
else
exec "!gcc -Wall -o %:r %:t && ./%:r"
endif
elseif &filetype == "cpp"
if WINDOWS()
exec "!g++ -Wall -std=c++11 -o %:r %:t && %:r.exe"
else
" exec "!g++ -Wall -std=c++11 -o %:r %:t && ./%:r"
exec "!clang++ -Wall -std=c++14 `pkg-config --cflags` -o %:r %:t && ./%:r"
" --libs opencv " add openvcv support
" -ggdb " add gdb support
endif
elseif &filetype == "d"
if WINDOWS()
exec "!dmd -wi %:t && %:r.exe"
else
exec "!dmd -wi %:t && ./%:r"
endif
elseif &filetype == "go"
exec "!go run %:t"
elseif &filetype == "rust"
if WINDOWS()
exec "!rustc %:t && %:r.exe"
else
exec "!rustc %:t && ./%:r"
endif
elseif &filetype == "java"
exec "!javac %:t && java %:r"
elseif &filetype == "groovy"
exec "!groovy %:t"
elseif &filetype == "scala"
exec "!scala %:t"
elseif &filetype == "clojure"
exec "!clojure -i %:t"
elseif &filetype == "cs"
exec "!mcs %:t && mono %:r.exe"
elseif &filetype == "fsharp"
if WINDOWS()
exec "!fsc %:t && %:r.exe"
else
exec "!fsharpc %:t && ./%:r.exe"
endif
elseif &filetype == "scheme" || &filetype == "racket"
exec "!racket -fi %:t"
elseif &filetype == "lisp"
exec "!sbcl --load %:t"
elseif &filetype == "ocaml"
if WINDOWS()
exec "!ocamlc -o %:r.exe %:t && %:r.exe"
else
exec "!ocamlc -o %:r %:t && ./%:r"
endif
elseif &filetype == "haskell"
if WINDOWS()
exec "!ghc -o %:r %:t && %:r.exe"
else
exec "!ghc -o %:r %:t && ./%:r"
endif
elseif &filetype == "lua"
exec "!lua %:t"
elseif &filetype == "perl"
exec "!perl %:t"
elseif &filetype == "php"
exec "!php %:t"
elseif &filetype == "python"
exec "!python3 %:t"
elseif &filetype == "ruby"
exec "!ruby %:t"
elseif &filetype == "elixir"
exec "!elixir %:t"
elseif &filetype == "julia"
exec "!julia %:t"
elseif &filetype == "dart"
exec "!dart %:t"
elseif &filetype == "haxe"
exec "!haxe -main %:r --interp"
elseif &filetype == "r"
exec "!Rscript %:t"
elseif &filetype == "coffee"
exec "!coffee -c %:t && node %:r.js"
elseif &filetype == "ls"
exec "!lsc -c %:t && node %:r.js"
elseif &filetype == "typescript"
" exec "!tsc %:t && node %:r.js"
exec "!npx ts-node %:r.ts"
elseif &filetype == "javascript"
" exec "!node --experimental-modules %:t"
exec "!node %:t"
elseif &filetype == "sh"
exec "!bash %:t"
elseif &filetype == "applescript"
exec "!osascript %:t"
endif
endfunc
" 生成cscope和tags文件
function! Do_CsTag()
let dir = getcwd()
if filereadable("tags")
if WINDOWS()
let tagsdeleted=delete(dir."\\"."tags")
else
let tagsdeleted=delete("./"."tags")
endif
if(tagsdeleted!=0)
echohl WarningMsg | echo "Fail to do tags! I cannot delete the tags" | echohl None
return
endif
endif
if has("cscope")
silent! execute "cs kill -1"
endif
if filereadable("cscope.files")
if WINDOWS()
let csfilesdeleted=delete(dir."\\"."cscope.files")
else
let csfilesdeleted=delete("./"."cscope.files")
endif
if(csfilesdeleted!=0)
echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.files" | echohl None
return
endif
endif
if filereadable("cscope.out")
if WINDOWS()
let csoutdeleted=delete(dir."\\"."cscope.out")
else
let csoutdeleted=delete("./"."cscope.out")
endif
if(csoutdeleted!=0)
echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.out" | echohl None
return
endif
endif
if(executable('ctags'))
"silent! execute "!ctags -R --c-types=+p --fields=+S *"
silent! execute "!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q ."
endif
if(executable('cscope') && has("cscope") )
if WINDOWS()
silent! execute "!find . -name '*.h' -o -name '*.c' -o -name '*.cpp' -o -name '*.java' -o -name '*.cs' > cscope.files"
else
silent! execute "!dir /s/b *.c,*.cpp,*.h,*.java,*.cs >> cscope.files"
endif
silent! execute "!cscope -b"
execute "normal :"
if filereadable("cscope.out")
execute "cs add cscope.out"
endif
endif
endfunction
" Append modeline after last line in buffer.
" Use substitute() instead of printf() to handle '%%s' modeline in LaTeX
" files.
function! AppendModeline()
let l:modeline = printf(" vim: set ts=%d sw=%d tw=%d %set :",
\ &tabstop, &shiftwidth, &textwidth, &expandtab ? '' : 'no')
let l:modeline = substitute(&commentstring, "%s", l:modeline, "")
call append(line("$"), l:modeline)
endfunction
function! RemoveOldViewFiles()
exe 'find '.$VIMHOME.'/view/* -mtime +90 -exec rm {} \;'
endfunction
function! SetCurLineNum()
let g:nal_cur_line_num = line("v")
endfunction
function! AddLineNum()
let num1 = line("v")
let num2 = num1 - g:nal_cur_line_num + 1
let num2 = " " . num2
"echo num2
return num2
endfunction
function! SetColorColumn()
let col_num = virtcol(".")
let cc_list = split(&cc, ',')
if count(cc_list, string(col_num)) <= 0
" cc(colorcolumn)选项需要vim7.3以上版本才支持.
execute "set cc+=".col_num
else
execute "set cc-=".col_num
endif
endfunction
" Remove trailing whitespace when writing a buffer, but not for diff files.
" From: Vigil
function! RemoveTrailingWhitespace()
if &ft != "diff"
let b:curcol = col(".")
let b:curline = line(".")
silent! %s/\(\[.*\]\[.*\]\)\s\+$/\1@@@@@@@@/
silent! %s/\s\+$//
silent! %s/\(\s*\n\)\+\%$//
silent! %s/\(\[.*\]\[.*\]\)@@@@@@@@$/\1 /
call cursor(b:curline, b:curcol)
endif
endfunction
" Toggle to ZenMode
" https://github.com/mmai/vim-zenmode/blob/master/plugin/zenmode.vim
func! ZenMode()
let g:zenmode_width = 100
let s:sidebar = ( winwidth( winnr() ) - g:zenmode_width - 2 ) / 2
" Create the left sidebar
exec("silent leftabove " . s:sidebar . "vsplit new")
setlocal noma
setlocal nocursorline
setlocal nonumber
silent! setlocal norelativenumber
setlocal statusline=%#LineNr# " change statusline background color
wincmd l
" Create the right sidebar
exec("silent rightbelow " . s:sidebar . "vsplit new")
setlocal noma
setlocal nocursorline
setlocal nonumber
silent! setlocal norelativenumber
wincmd h
" 把左边的底部波浪号隐藏
exec("hi NonText ctermfg=white")
" 分隔边框的颜色
exec("hi VertSplit ctermbg=white ctermfg=white")
call NumberToggle()
endfunc
" }
" }
" Setting {
" Basic {
syntax enable " 打开语法高亮
syntax on " 开启文件类型侦测
filetype indent on " 针对不同的文件类型采用不同的缩进格式
filetype plugin on " 针对不同的文件类型加载对应的插件
filetype plugin indent on " 启用自动补全
set visualbell t_vb= " 关闭visual bell/声音
" set t_Co=256 " 设置文字可以显示多少种颜色, 历史原因可能是比 8-bit 色彩更少, 可能比 8-bit 终端更早
au GuiEnter * set t_vb= " 关闭beep/屏闪
" set t_ti= t_te= " 退出 vim 后,vim 的内容仍显示在屏幕上
set backspace=2 " 设置退格键可用
set ruler " 右下角显示光标位置的状态行
set hidden " 允许在有未保存的修改时切换缓冲区
set laststatus=2 " 开启状态栏信息
set cmdheight=2 " 命令行的高度,默认为1,这里设为2
" set bsdir=buffer " 设定文件浏览器目录为当前目录
" set autochdir " sometimes can not work
autocmd BufEnter * silent! lcd %:p:h
set wildmenu " 在命令行下显示匹配的字段到状态栏里面
" set cursorcolumn " 突出显示当前列
set history=500 " keep 500 lines of command line history
silent! set mouse=a " 启用鼠标
set cursorline " 突出显示当前行
" set tw=78 "超过80个字符就折行(textwrap)
" set viminfo='20,\"50 " read/write a .viminfo file, don't store more than 50 lines of registers
set display=lastline " 不要显示@@@@@
" set conceallevel=2 " 隐藏想要隐藏的字符
" set fillchars+=vert:\ " 设置 split bar 的内容字符
" set foldcolumn=2 " 左侧窗边的宽度
" 光标的上下方至少保留显示的行数
set scrolloff=5
set showmatch " 显示括号配对情况
" set lsp=0 " 设置行间距
" => Modify word boundary characters
" insert schema, ctrl+w and other keys likes emacs
set iskeyword+=- " remove - as a word boundary
set iskeyword+=$
" }
" 文件配置 {
if has("multi_byte")
set fo+=mB " formatoptions 打开断行模块对亚洲语言支持
" if v:lang =~? '^\(zh\)\|\(ja\)\|\(ko\)'
" set ambiwidth=double " 自动用宽字符显示(如果全角字符不能识别)
" endif
endif
" 相对行号 {
if v:version > 703
set relativenumber number
" 插入模式下用绝对行号,普通模式下用相对
" augroup numbertoggle
" autocmd!
" autocmd BufEnter,FocusGained,InsertLeave * set relativenumber " nonumber
" autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber number
" augroup END
function! NumberToggle()
if(&relativenumber == 1)
set norelativenumber nonumber
else
set relativenumber number
endif
endfunc
nnoremap <F2> :call NumberToggle()<cr>
" no num and relative
" nnoremap <leader><F3> :set relativenumber!<CR>:set nu!<CR>
" imap <leader><F3> :set relativenumber!<CR>:set nu!<CR>
endif
" }
set list " 显示特殊字符,其中Tab使用高亮竖线代替,尾部空白使用高亮点号代替
" set showbreak=↪\ " 显示换行后新行的首字符
set listchars=tab:→\ ,extends:›,precedes:‹,nbsp:␣,trail:·
" set listchars=tab:\|\ ,trail:. " 设置tab/尾部字符用什么填充
" set fileformats=unix " 设定换行符
set wrap
set linebreak " 自动断行, 用 breakat 控制
set enc=utf-8 " 设置编码
" set fenc=utf-8 " 设置文件编码
set fencs=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936 " 设置文件编码检测类型及支持格式
set shortmess+=filmnrxoOtT " Abbrev. of messages (avoids 'hit enter')
set viewoptions=folds,options,cursor,unix,slash " Better Unix / Windows compatibility
" set virtualedit=onemore " Allow for cursor beyond last character
set autoread " 当文件在外部被修改时自动更新该文件
set writebackup " Make a backup before overwriting a file. The backup is removed after the file was successfully written, unless the 'backup' option is also on.
set nobackup " 不生成备份文件
set noswapfile " 不生成交换文件
" restore last postion in file to $VIMHOME/view
" 打开自动定位到最后编辑的位置, 需要确认 .viminfo 当前用户可写
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
if v:version > 703
set undofile " 持续保留操作记录,默认filename.un~, valid feature for `vim --version` have +persistent_undo
if empty(glob("$VIMHOME/_undodir"))
call mkdir(expand("$VIMHOME/_undodir"))
endif
set undodir=$VIMHOME/_undodir
set undolevels=1000 " maximum number of changes that can be undone"
endif
" if !exists("g:no_vimrc_bundles")
" 由于不同版本的 vim 导致 mkview 出现越来越多问题,弃用
" autocmd BufWinLeave *.* if expand('%') != '' && &buftype == '' | mkview | endif
" autocmd BufRead *.* if expand('%') != '' && &buftype == '' | silent loadview | endif
" *.* is better for me than using just *, as when I load Vim it defaults to [No File]
" au BufWinLeave ?* silent mkview 1 " 星号前面的问号是忽略未命名文件
" 状态保存在 ~/.vim/view 文件夹,如果保存了之后,修改了 filetype 的 syntax 属性,需要删除 view 才能更新
" endif
" }
" GUI & WIN {
" 设置着色模式和字体
if WINDOWS()
" 使用GUI界面时的设置
if has("gui_running")
" 启动gvim时窗口的大小
" set lines=42 columns=170
" 启动时自动最大化窗口
" au GUIEnter * simalt ~x
" winpos 20 20 " 指定窗口出现的位置,坐标原点在屏幕左上角
" set lines=20 columns=90 " 指定窗口大小,lines为高度,columns为宽度
set guioptions+=c " 使用字符提示框
set guioptions-=m " 隐藏菜单栏
set guioptions-=T " 隐藏工具栏
set guioptions-=L " 隐藏左侧滚动条
set guioptions-=r " 隐藏右侧滚动条
" set guioptions-=b " 隐藏底部滚动条
" set showtabline=1 " 隐藏Tab栏
set guioptions+=aA " get some autoselect interaction with the system clipboard
" colortheme list: molokai autumn blackboard asu1dark busybee tomorrow
" colorscheme solarized " deep blue
" colorscheme morning " white
" colorscheme desertEx
" let g:zenburn_transparent = 1 " black
let g:zenburn_high_Contrast = 1
silent! colorscheme zenburn " grey, my fav
" set font
" https://github.com/runsisi/consolas-font-for-powerline
set guifont=Powerline\ Consolas:h11:cANSI,Consolas\ NF:h11:cANSI,Consolas:h11,Inconsolata:h12
" https://gist.github.com/kevinis/c788f85a654b2d7581d8
" set guifont=Monaco\ for\ Powerline:h12:cANSI
set renderoptions=type:directx,renmode:5
" set guifont=Monaco:h11
" set guifont=Source\ Code\ Pro\ Regular:h15
" set guifont=YaHei\ Consolas\ Hybrid:h13
" set guifont=Source\ Code\ Pro:h13
else
silent! colorscheme CodeFactoryv3
" colorscheme ir_black
" 兼容windows下cmd的gb2312
" set enc=cp936
" help encoding-table
set termencoding=cp936
" In order to reload a file with proper encoding you can do:
" :e! ++enc=<the_encoding>.
" dos里面<backspace>和<c-h>完全链接了,要取消<c-h>的映射
iunmap <c-h>
endif
else
if has("gui_running")
if has("gui_gtk2")
set guioptions=egitcaA " 与Windows类似"
set guifont=Monaco\ 14
elseif has("gui_macvim")
set guifont=Monaco\ for\ Powerline:h12
set guifontwide=HiraginoSansGB-W3:h12
" set guifontwide=Go\ Mono\ for\ Powerline:h12
set guioptions-=r " 隐藏右侧滚动条
set guioptions-=L " 隐藏左侧滚动条
end
" set guifont=Monaco\ 13
" set guifontwide=HiraginoSansGB-W3:h15
" set guifont=YaHei\ Consolas\ Hybrid:h13
set background=light
silent! colorscheme solarized
set lines=38 columns=140
" 在 macvim 中,不支持
" set nu!
else
" colortheme list: ir_black grb256 BusyBee pt_black solarized xoria256
" silent! colorscheme pt_black
silent! colorscheme solarized
" Solarized 主题
let g:solarized_termcolors=16 " 16 | 256
let g:solarized_termtrans=1 " 0 | 1
let g:solarized_contrast="normal" " 'normal' | 'high' or 'low'
let g:solarized_visibility="normal" " 'normal' | 'high' or 'low'
let g:solarized_bold = 1 " 1 | 0
" highlight LineNr ctermbg=none ctermfg=grey " 设置行号背景为 none
" g:solarized_degrade = 0 | 1
" g:solarized_underline = 1 | 0
" g:solarized_italic = 1 | 0
" g:solarized_contrast = “normal”| “high” or “low”
if exists("g:color_dark")
set background=dark
else
set background=light
endif
highlight LineNr ctermbg=none ctermfg=none " 设置行号背景为 none
if &background == 'light'
hi CursorLine term=bold cterm=bold ctermbg=7 guibg=Grey90
hi Folded term=bold,underline cterm=bold,underline ctermfg=11 ctermbg=7 guifg=DarkBlue guibg=LightGrey
endif
endif
endif
" pure vim {
if get(g:, 'colors_name', 'default') == 'default'
if &background == 'light'
hi CursorLine term=bold cterm=bold ctermbg=7 guibg=Grey90
hi Folded term=bold,underline cterm=bold,underline ctermfg=11 ctermbg=7 guifg=DarkBlue guibg=LightGrey
endif
endif
" }
" }
" 代码折叠 {
set foldenable
" 折叠方法
" manual 手工折叠
" indent 使用缩进表示折叠
" expr 使用表达式定义折叠
" syntax 使用语法定义折叠
" diff 对没有更改的文本进行折叠
" marker 使用标记进行折叠, 默认标记是 {{{ 和 }}}, 可以自定义为 `set foldmarker={,}`
set foldmethod=indent
set foldlevel=99
" 代码折叠自定义快捷键 <leader>zz
nnoremap <space> za " 用空格来切换折叠状态
let g:FoldMethod = 0
map <leader>zz :call ToggleFold()<cr>
fun! ToggleFold()
if g:FoldMethod == 0
exe "normal! zM"
let g:FoldMethod = 1
else
exe "normal! zR"
let g:FoldMethod = 0
endif
endfun
" }
" 缩进配置 {
set smartindent " 自动缩进
set autoindent " 自动对齐
" tab 键宽度为4空格
set tabstop=4
" 每一次缩进对应的空格数
set shiftwidth=4
" 按退格键可以一次删掉4个空格
set softtabstop=4
set smarttab
" 将 tab 自动转化成空格 (需要输入真正的Tab键时,使用 Ctrl+V + Tab)
set expandtab
" 缩进时,取整
set shiftround
set cindent
" 详细的tab设置:http://blog.chinaunix.net/uid-24774106-id-3396220.html
set smarttab "在行首按TAB将加入sw个空格,否则加入ts个空格;按Backspace可以删除4个空格
" }
" 粘贴模式 {
" 在插入模式下按 <F3> 进入粘贴模式,这时候粘贴复制过来的代码不会触发自动缩进
set pastetoggle=<F3>
" 离开插入模式时,关闭粘贴模式
autocmd InsertLeave * set nopaste
" }"
" Search {
set incsearch " 开启实时搜索功能,查询时非常方便,如要查找book单词,当输入到/b时,会自动找到第一个b开头的单词,当输入到/bo时,会自动找到第一个bo开头的单词
set hlsearch " 开启高亮显示结果
set nowrapscan " 搜索到文件两端时不重新搜索
set ic " 忽略大小写查找
" 搜索正则匹配规则改变 见帮助 :h magic
set magic
" 搜索模式为默认更先进的正则规则
" nnoremap / /\v
" vnoremap / /\v
" }
" Statusline {
" 当没有 airline 插件的时候使用这里的自定义
if !&statusline
" https://shapeshed.com/vim-statuslines/
" http://vim.wikia.com/wiki/Writing_a_valid_statusline
" http://learnvimscriptthehardway.stevelosh.com/chapters/17.html
function! GitBranch()
return system("git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'")
endfunction
function! StatuslineGit()
let l:branchname = GitBranch()
return strlen(l:branchname) > 0?' '.l:branchname.' ':''
endfunction
set statusline=
set statusline+=%#PmenuSel# " change background color
" set statusline+=[%n] " buffer num
" set statusline+=%{StatuslineGit()}
set statusline+=%#LineNr# " change background color
set statusline+=\ %f " file name
" set statusline+=\ %.20F " file path, length limit 20%
set statusline+=%m\ " check modify status
set statusline+=%= " align right
set statusline+=%#CursorColumn#
set statusline+=\ %y
set statusline+=\ %{&fileencoding?&fileencoding:&encoding}
set statusline+=\[%{&fileformat}\] " fileformat
set statusline+=\ %l/%L:%c
set statusline+=\ %p%%
set statusline+=\ " space at end
endif
" }
" => Wild Ignore {
" 忽略这些扩展文件
" Disable output and VCS files
set wildignore+=*.rbc,*.rbo,*.gem,.git,.svn
" Disable image files
set wildignore+=*.psd,*.png,*.jpg,*.gif,*.jpeg
" Disable archive files
set wildignore+=*.zip,*.tar.gz,*.tar.bz2,*.rar,*.tar.xz
" Ignore bundler and sass cache
set wildignore+=*/vendor/gems/*,*/vendor/cache/*,*/.bundle/*,*/.sass-cache/*
" Disable temp and backup files
set wildignore+=*.sw?,*~,._*,*.un~
" WP Language files
set wildignore+=*.pot,*.po,*.mo
" Fonts and such
set wildignore+=*.eot,*.eol,*.ttf,*.otf,*.afm,*.ffil,*.fon,*.pfm,*.pfb,*.woff,*.svg,*.std,*.pro,*.xsf
set wildignore+=*.aux,*.out,*.toc " LaTeX intermediate files
set wildignore+=*.so,*.out,*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
set wildignore+=*.luac " Lua byte code
set wildignore+=*.pyc " Python byte code
set wildignore+=*.class" Python byte code
set wildignore+=*.spl " compiled spelling word lists
set wildignore+=*/tmp/*,.DS_Store " MacOSX/Linux
" }
" }
" Scene Setting {
" ManPage {
" manpageview phpfunctionname.php
" 可以使用快捷键K查询
" 说明,比如你在centos里面装了man-pages,当你用K查询的时候,自动会弹出man 你光标下面的词
" manpageview 替代了插件pydoc.vim
"
" }
" Markdown {
" Instant Preview Markdown
let g:instant_markdown_autostart = 0
map <leader>rp :InstantMarkdownPreview<CR>
let tlist_markdown_settings = 'markdown;c:content;f:figures;t:tables;h:headlines'
" au BufRead,BufNewFile *.{md,mdown,mkd,mkdn,markdown,mdwn} set ft=markdown
" au BufRead,BufNewFile *.{md,mdown,mkd,mkdn,markdown,mdwn} set iskeyword+=[
" au BufRead,BufNewFile *.{md,mdown,mkd,mkdn,markdown,mdwn} set iskeyword-=_
" au BufRead,BufNewFile *.{md,mdown,mkd,mkdn,markdown,mdwn} set conceallevel=2
" au FileType markdown,MARKDOWN set iskeyword+=[
" au FileType markdown,MARKDOWN set iskeyword-=_
" au BufWritePre *{md,mdown,mkd,mkdn,markdown,mdwn} call RemoveTrailingWhitespace()
" :Toch 水平底部添加 Toc, 这个可以复制到正文里面
" ]] go to next header.
" [[ go to previous header. Contrast with ]c.
" }
" Python {
" python highlight
let python_highlight_all = 1
let b:python_version_2 = 1
let g:python_version_2 = 1
au BufRead *.wsgi setl filetype=python
au BufNewFile,BufRead *.py,*.pyw
\ set tabstop=4 |
\ set softtabstop=4 |
\ set shiftwidth=4 |
\ set textwidth=79 |
\ set expandtab |
\ set autoindent |
\ set fileformat=unix |
" Use UNIX (\n) line endings.
au BufNewFile *.py,*.pyw,*.c,*.h set fileformat=unix
" Display tabs at the beginning of a line in Python mode as bad.
" au BufRead,BufNewFile *.py,*.pyw match BadWhitespace /^\t\+/
" Make trailing whitespace be flagged as bad.
" au BufRead,BufNewFile *.py,*.pyw,*.c,*.h match BadWhitespace /\s\+$/
" 支持Virtualenv虚拟环境
" 上面“转到定义”功能的一个问题,就是默认情况下Vim不知道virtualenv虚拟环境的情况,所以你必须在配置文件中添加下面的代码,使得Vim和YouCompleteMe能够发现你的虚拟环境:
" python with virtualenv support
" py << EOF
" import os
" import sys
" if 'VIRTUAL_ENV' in os.environ:
" project_base_dir = os.environ['VIRTUAL_ENV']
" activate_this = os.path.join(project_base_dir, 'bin/activate_this.py')
" execfile(activate_this, dict(__file__=activate_this))
" EOF
" 这段代码会判断你目前是否在虚拟环境中编辑,然后切换到相应的虚拟环境,并设置好你的系统路径,确保YouCompleteMe能够找到相应的site packages文件夹。
" 上面的代码似乎已经被下面的插件智能解 决
" https://github.com/jmcantrell/vim-virtualenv
" 如果有一天一直使用 python 可以考虑把 python 放在单独的一个文件配置中, 参考这篇文章
" https://segmentfault.com/a/1190000003962806
" }
" PHP {
let g:phpcomplete_relax_static_constraint = 1
let g:phpcomplete_complete_for_unknown_classes = 1
let g:phpcomplete_search_tags_for_variables = 1
let g:phpcomplete_mappings = {
\ 'jump_to_def': ',g',
\ }
"只有在是PHP文件时,才启用PHP补全
function! AddPHPFuncList()
set dictionary+=$HOME/.vim/vimfiles/resource/php-offical.dict
set complete-=k complete+=k
endfunction
" Map <leader>el to error_log value
" takes the whatever is under the cursor and wraps it in error_log( and
" print_r( with parameter true and a label
au FileType php nnoremap <leader>el ^vg_daerror_log( '<esc>pa=' . print_r( <esc>pa, true ) );<cr><esc>
au FileType php call AddPHPFuncList()
au FileType php setlocal omnifunc=syntaxcomplete#Complete
au BufNewFile,BufRead *.phtml set filetype=php
" set tags+= ~/.vim/vimfiles/resource/tags-php
" autocmd FileType php setlocal omnifunc=phpcomplete#CompleteTags
" 除了使用Tab这个补全的方式,还可以使用Ctrl+x,Ctrl+o来补全上面文件的内置函数
" function! RunPhpcs()
" let l:filename=@%
" let l:phpcs_output=system('phpcs --report=csv --standard=YMC '.l:filename)
" let l:phpcs_list=split(l:phpcs_output, "\n")
" unlet l:phpcs_list[0]
" cexpr l:phpcs_list
" cwindow
" endfunction
" set errorformat+=\"%f\"\\,%l\\,%c\\,%t%*[a-zA-Z]\\,\"%m\"
" command! Phpcs execute RunPhpcs()
" php debug
let g:vdebug_keymap = {
\ "run" : "<F5>",
\ "set_breakpoint" : "<F9>",
\ "run_to_cursor" : "<F1>",
\ "get_context" : "<F2>",
\ "detach" : "<F7>",
\ "step_over" : "<F10>",
\ "step_into" : "<F11>",
\ "step_out" : '<leader><F11>',
\ "close" : '<leader><F5>',
\ "eval_under_cursor" : "<Leader>ec",
\ "eval_visual" : "<Leader>ev",
\}
let g:vdebug_options = {
\ "port" : 9000,
\ "server" : 'localhost',
\ "timeout" : 20,
\ "on_close" : 'detach',
\ "break_on_open" : 0,
\ "path_maps" : {},
\ "debug_window_level" : 0,
\ "debug_file_level" : 0,
\ "debug_file" : "",
\ "watch_window_style" : 'expanded',
\ "marker_default" : '*',
\ "marker_closed_tree" : '+',
\ "marker_open_tree" : '-'
\}
" 要让vim支持php/js的错误查询,先安装syntastic插件
" 然后用php对应的版本pear install PHP_CodeSniffer-2.0.0a2
" shell测试:phpcs index.php
" phpcs,tab 4个空格,编码参考使用CodeIgniter风格
" let g:syntastic_phpcs_conf = "--tab-width=3 --standard=Zend"
" let g:syntastic_phpcs_conf = "--tab-width=4 --standard=CodeIgniter"
" 也可以在cli中执行下面的命令
" phpcs --config-set default_standard Zend
" 如果怕被phpcs提示的错误吓倒,可以把Zend改成none,这样就只会提示一些常见的错误
"
let g:phpqa_messdetector_ruleset = ''
let g:phpqa_messdetector_cmd = '/usr/bin/phpmd'
" 在打开文件的时候检查
let g:phpqa_messdetector_autorun = 0
" }
" RUBY {
" 针对部分语言取消指定字符的单词属性
" au FileType ruby set iskeyword+=!
" au FileType ruby set iskeyword+=?
" 对部分语言设置单独的缩进
" au FileType ruby,eruby set shiftwidth=2
" au FileType ruby,eruby set tabstop=2
" auto completed
" let g:rubycomplete_buffer_loading = 1
" let g:rubycomplete_classes_in_global = 1
" let g:rubycomplete_rails = 1
" autocmd FileType ruby compiler ruby
" }
" JavaScript & Node {
" F 格式化当前页面 js,html,css. 可选中局部格式化
" au FileType javascript,coffee,slim,jade set shiftwidth=2
" au FileType javascript,offee,slim,jade set tabstop=2
" au BufRead,BufNewFile *.scss set filetype=scss