-
Notifications
You must be signed in to change notification settings - Fork 50
/
vimrc
1119 lines (1112 loc) · 34.4 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
scriptencoding utf-8
" ========================================================================
" 依云(lilydjwg) 的 vimrc
" 我的博客: https://blog.lilydjwg.me/
"
" 整个配置仅适用于本人
" 不过,其中的部分配置很可能非常适合你哦~~
" 不要整个地照搬,只复制对你自己有用的部分!
"
" 有任何意见和建议,或者其它想说的,可以到我的博客留言。
"
" 许可:GPLv3
" ========================================================================
" 其他文件[[[1
try
packadd! matchit
catch /.*/
runtime macros/matchit.vim
endtry
runtime vimrc_example.vim
"]]]
" 我的设置
" 函数[[[1
" 复制缓冲区到新标签页[[[2
function Lilydjwg_copy_to_newtab()
let temp = tempname()
try
let nr = bufnr('%')
exec "mkview" temp
tabnew
silent exec "source" temp
finally
call delete(temp)
endtry
endfunction
" 删除所有未显示且无修改的缓冲区以减少内存占用[[[2
function Lilydjwg_cleanbufs()
for bufNr in filter(range(1, bufnr('$')),
\ 'buflisted(v:val) && !bufloaded(v:val)')
execute bufNr . 'bdelete'
endfor
endfunction
" 转成 HTML,只要 pre 标签部分[[[2
" http://bootleq.blogspot.com/2012/12/tohtml-html-document-function-tohtmldoc.html
function Lilydjwg_to_html(line1, line2)
let save_number = get(g:, 'html_number_lines', -1)
let g:html_number_lines = 0
call tohtml#Convert2HTML(a:line1, a:line2)
setlocal buftype=nofile bufhidden=hide noswapfile nobuflisted
call search("<pre[^<]*>")
normal! dit
%delete _
let @" = '<pre>' . substitute(@", '\v^\n\s*', '', '') . '</pre>'
call setline(1, split(@", '\n'))
if save_number > -1
let g:html_number_lines = save_number
else
unlet g:html_number_lines
endif
endfunction
" 获取可读的文件大小[[[2
function Lilydjwg_getfsize(file)
let size = getfsize(a:file)
if has('python3')
try
py3 from myutils import filesize
return py3eval('filesize('.size.')')
catch /.*/
endtry
endif
return size . 'B'
endfunction
" 打开 NERDTree,使用当前文件目录或者当前目录[[[2
function Lilydjwg_NERDTreeOpen()
if exists("t:NERDTreeBufName")
NERDTreeToggle
else
try
NERDTree `=expand('%:h')`
catch /E121/
NERDTree `=getcwd()`
endtry
endif
endfunction
" Perl-style quoted lists[[[2
function Lilydjwg_qw()
let in = input('qw(')
return py3eval('LilyQw("'.escape(in, '"\').'")')
endfunction
" 使用分隔符连接多行 [[[2
function Lilydjwg_join(sep, bang) range
if a:sep[0] == '\'
let sep = strpart(a:sep, 1)
else
let sep = a:sep
endif
let lines = getline(a:firstline, a:lastline)
if a:firstline == 1 && a:lastline == line('$')
let dellast = 1
else
let dellast = 0
endif
exe a:firstline . ',' . a:lastline . 'd_'
if a:bang != '!'
call map(lines, "substitute(v:val, '^\\s\\+\\|\\s\\+$', '', 'g')")
endif
call append(a:firstline-1, join(lines, sep))
if dellast
$d_
endif
endfunction
" 切换显示行号/相对行号/不显示 [[[2
function Lilydjwg_toggle_number()
if &nu && &rnu
set nonu nornu
elseif &nu && !&rnu
set rnu
else
set nu
endif
endfunction
" 更改缩进[[[2
function Lilydjwg_reindent(...)
if a:0 != 2
echoerr "需要两个参数"
endif
let save_et = &et
let save_ts = &ts
try
let &ts = a:1
set noet
retab!
let &ts = a:2
set et
retab!
let &l:sw = a:2
finally
let &et = save_et
let &ts = save_ts
endtry
endfunction
" 将当前窗口置于屏幕中间(全屏时用)[[[2
function CenterFull()
on
vs
ene
setl nocul
setl nonu
40winc |
winc l
vs
winc l
ene
setl nocul
setl nonu
40winc |
winc h
redr!
endfunction
" 使用 colorpicker 程序获取颜色值(hex/rgba)[[[2
function Lilydjwg_colorpicker()
if exists("g:last_color")
let color = substitute(system("colorpicker ".shellescape(g:last_color)), '\n', '', '')
else
let color = substitute(system("colorpicker"), '\n', '', '')
endif
if v:shell_error == 1
return ''
elseif v:shell_error == 2
" g:last_color 值不对
unlet g:last_color
return Lilydjwg_colorpicker()
else
let g:last_color = color
return color
endif
endfunction
" 更改光标下的颜色值(hex/rgba/rgb)[[[2
function Lilydjwg_changeColor()
let color = Lilydjwg_get_pattern_at_cursor('\v\#[[:xdigit:]]{6}(\D|$)@=|<rgba\((\d{1,3},\s*){3}[.0-9]+\)|<rgb\((\d{1,3},\s*){2}\d{1,3}\)')
if color == ""
echohl WarningMsg
echo "No color string found."
echohl NONE
return
endif
let g:last_color = color
let new_color = Lilydjwg_colorpicker()
if new_color != ''
exe 'normal! eF'.color[0]
call setline('.', substitute(getline('.'), '\%'.col('.').'c\V'.color, new_color, ''))
endif
endfunction
" Locate and return character "above" current cursor position[[[2
function LookFurther(down)
"来源 http://www.ibm.com/developerworks/cn/linux/l-vim-script-1/,有修改
"Locate current column and preceding line from which to copy
let column_num = virtcol('.')
let target_pattern = '\%' . column_num . 'v.'
let target_pattern_1 = '\%' . (column_num+1) . 'v.'
" FIXed 当光标位于如下 | 所示位置时,将取得错误的虚拟列号
" /中文
" |中文
" 光标下的字符是多字节的?
" echo '['.matchstr(getline('.'), target_pattern).']'
if matchstr(getline('.'), target_pattern) == '' &&
\ matchstr(getline('.'), target_pattern_1) != ''
let column_num -= 1
" 上面的字符可能是英文(前者)或者中文(后者)的
let target_pattern = '\%' . column_num . 'v.\|' . target_pattern
endif
if a:down
let target_line_num = search(target_pattern, 'nW')
else
let target_line_num = search(target_pattern, 'bnW')
endif
"If target line found, return vertically copied character
if !target_line_num
return ""
else
return matchstr(getline(target_line_num), target_pattern)
endif
endfunction
inoremap <silent> <C-Y> <C-R><C-R>=LookFurther(0)<CR>
inoremap <silent> <M-y> <C-R><C-R>=LookFurther(1)<CR>
" 对齐命令[[[2
function Lilydjwg_Align(type) range
try
let pat = g:Myalign_def[a:type]
catch /^Vim\%((\a\+)\)\=:E716/
echohl ErrorMsg
echo "对齐方式" . a:type . "没有定义"
echohl None
return
endtry
call Align#AlignPush()
call Align#AlignCtrl(pat[0])
if len(pat) == 3
call Align#AlignCtrl(pat[2])
endif
exe a:firstline.','.a:lastline."call Align#Align(0, '". pat[1] ."')"
call Align#AlignPop()
endfunction
function Lilydjwg_Align_complete(ArgLead, CmdLine, CursorPos)
return filter(keys(g:Myalign_def), 'stridx(v:val, a:ArgLead) == 0')
endfunction
" 退格删除自动缩进 [[[2
function! Lilydjwg_checklist_bs(pat)
" 退格可清除自动出来的列表符号
if getline('.') =~ a:pat
let ind = indent(line('.')-1)
if !ind
let ind = indent(line('.')+1)
endif
call setline(line('.'), repeat(' ', ind))
return ""
else
return "\<BS>"
endif
endfunction
" 字典补全 <C-X><C-K> 与 <C-K>[[[2
function Lilydjwg_dictcomplete()
if pumvisible()
return "\<C-K>"
else
return "\<C-X>\<C-K>"
endif
endfunction
" 返回当前日期的中文表示[[[2
function Lilydjwg_zh_date()
let d = strftime("%Y年%m月%d日")
let d = substitute(d, '[年月]\@<=0', '', 'g')
return d
endfunction
" 关闭某个窗口[[[2
function Lilydjwg_close(winnr)
let winnum = bufwinnr(a:winnr)
if winnum == -1
return 0
endif
" Goto the workspace window, close it and then come back to the
" original window
let curbufnr = bufnr('%')
exe winnum . 'wincmd w'
close
" Need to jump back to the original window only if we are not
" already in that window
let winnum = bufwinnr(curbufnr)
if winnr() != winnum
exe winnum . 'wincmd w'
endif
return 1
endfunction
" 补全 So 命令[[[2
function Lilydjwg_complete_So(ArgLead, CmdLine, CursorPos)
let path = 'so/' . a:ArgLead . '*'
let ret = split(globpath(&rtp, path), '\n')
call filter(ret, 'v:val =~ "\.vim$"')
" XXX 如果文件名特殊则可能不对
call map(ret, 'fnamemodify(v:val, '':t:r'')')
return ret
endfunction
" 取得光标处的匹配[[[2
function Lilydjwg_get_pattern_at_cursor(pat)
let col = col('.') - 1
let line = getline('.')
let ebeg = -1
let cont = match(line, a:pat, 0)
while (ebeg >= 0 || (0 <= cont) && (cont <= col))
let contn = matchend(line, a:pat, cont)
if (cont <= col) && (col < contn)
let ebeg = match(line, a:pat, cont)
let elen = contn - ebeg
break
else
let cont = match(line, a:pat, contn)
endif
endwhile
if ebeg >= 0
return strpart(line, ebeg, elen)
else
return ""
endif
endfunction
" 切换配色方案[[[2
function Lilydjwg_toggle_color()
let colors = ['pink_lily', 'lilypink', 'darkBlue', 'spring2']
" spring2 是增加了彩色终端支持的 spring
if !exists("g:colors_name")
let g:colors_name = 'pink_lily'
endif
let i = index(colors, g:colors_name)
let i = (i+1) % len(colors)
exe 'colorscheme' get(colors, i)
endfunction
" %xx -> 对应的字符(到消息)[[[2
function Lilydjwg_hexchar()
let chars = Lilydjwg_get_pattern_at_cursor('\(%[[:xdigit:]]\{2}\)\+')
if chars == ''
echohl WarningMsg
echo '在光标处未发现%表示的十六进制字符串!'
echohl None
return
endif
let str = substitute(chars, '%', '\\x', 'g')
exe 'echo "'. str . '"'
endfunction
" 用火狐打开链接[[[2
function Lilydjwg_open_url()
let s:url = Lilydjwg_get_pattern_at_cursor('\v%(https?|ftp)://[^]''" \t\r\n>*。,\`)]*')
if s:url == ""
echohl WarningMsg
echomsg '在光标处未发现URL!'
echohl None
else
echo '打开URL:' . s:url
if has("win32") || has("win64")
" start 不是程序,所以无效。并且,cmd 只能使用双引号
" call system("start '" . s:url . "'")
call system("cmd /q /c start \"" . s:url . "\"")
elseif has("mac")
call system("open '" . s:url . "'")
else
" call system("gnome-open " . s:url)
call system("xdg-open '" . s:url . "' &")
endif
endif
unlet s:url
endfunction
" Title Save [[[2
function Lilydjwg_TSave()
let line = getline(1)
if line =~ '^\s*$'
let line = getline(2)
endif
let line = substitute(line, '[:/\\]', '-', 'g')
let line = substitute(line, '^\s\+', '', 'g')
let line = substitute(line, '\s\+$', '', 'g')
let line = substitute(line, ' ', '\\ ', 'g')
let line = substitute(line, '\r', '', 'g')
exe 'sav ' . line . '.txt'
endfunction
" 切换 ve [[[2
function Lilydjwg_toggle_ve()
if &ve == 'all'
let &ve = ''
else
let &ve = 'all'
endif
endfunction
" 切换 ambiwidth [[[2
function Lilydjwg_toggle_ambiwidth()
if &ambiwidth == 'double'
let &ambiwidth = 'single'
else
let &ambiwidth = 'double'
endif
endfunction
" 是否该调用 cycle?[[[2
function Lilydjwg_trycycle(dir)
let pat = Lilydjwg_get_pattern_at_cursor('[+-]\?\d\+')
if pat
if a:dir ==? 'x'
return "\<C-X>"
else
return "\<C-A>"
end
else
let mode = mode() =~ 'n' ? 'w' : 'v'
let dir = a:dir ==? 'x' ? -1 : 1
return ":\<C-U>call Cycle('" . mode . "', " . dir . ", v:count1)\<CR>"
end
endfunction
" format the whole file [[[2
function Lilydjwg_formatall()
let v = winsaveview()
keepjumps normal! gg=G
call winrestview(v)
endfunction
" set 相关[[[1
" 一般设置[[[2
" maybe necessary when root
syntax on
set number
set smarttab
set expandtab
" 不要响铃,更不要闪屏
set visualbell t_vb=
" when will this cause problems?
set ttyfast
set title
" 不要包含标准错误,但是允许 Vim 初始化其默认值
autocmd VimEnter * set shellredir=>
autocmd GUIEnter * set t_vb=
" ! is for histwin to save tags
set viminfo='100,:10000,<50,s10,h,!
set history=10000
set wildmenu
set delcombine " 组合字符一个个地删除
set laststatus=2 " 总是显示状态栏
" 首先尝试最长的,接着轮换补全项
set wildmode=longest:full,full
set shiftround
set diffopt+=vertical,context:3,foldcolumn:0
if &diffopt =~ 'internal'
set diffopt+=indent-heuristic,algorithm:patience
endif
set fileencodings=ucs-bom,utf-8,gb18030,cp936,latin1
set fileformats=unix,dos,mac
set formatoptions=croqn2mB1
try
" Vim 7.4
set formatoptions+=j
catch /.*/
endtry
set nojoinspaces
set virtualedit=block
set nostartofline
" set guioptions=egmrLtai
set guioptions=acit
" 没必要,而且很多时候 = 表示赋值
set isfname-==
set nolinebreak
set nowrapscan
set scrolloff=5
set sessionoptions=blank,buffers,curdir,folds,help,options,tabpages,winsize,slash,unix,resize
set shiftwidth=2
set winaltkeys=no
set noequalalways
set listchars=eol:$,tab:>-,nbsp:␣
set display=lastline
set completeopt+=longest
try
set completeopt+=popup
set completepopup=border:off
catch /.*/
endtry
set maxcombine=4
set cedit=<C-Y>
set whichwrap=b,s,[,]
set tags+=./tags;
try
set matchpairs=(:),{:},[:],《:》,〈:〉,[:],(:),「:」,『:』,‘:’,“:”
catch /^Vim\%((\a\+)\)\=:E474/
endtry
" Avoid command-line redraw on every entered character by turning off Arabic
" shaping (which is implemented poorly).
if has('arabic')
set noarabicshape
endif
set wildignore+=*~,*.py[co],__pycache__,.*.swp
set shortmess-=S
if !has("patch-8.1.1270")
try
packadd! vim-searchindex
catch /.*/
endtry
endif
" will make termux mouse not work https://github.com/vim/vim/issues/7422
" if exists('&balloonevalterm')
" set balloonevalterm
" endif
try
set signcolumn=number
catch /.*/
endtry
set grepprg=grep\ -nH\ $*
if has('&clipboard')
set clipboard=autoselect,html,exclude:cons\|linux
endif
set tabpagemax=50
" make it unusable so it won't clash
set termwinkey=<C-\\>
set backup backupcopy=no
" Linux 与 Windows 等 [[[2
if has("gui_macvim")
set macmeta
end
if has("win32") || has("win64")
let g:vimfiles = split(&runtimepath, ',')[1]
let g:mytmpdir = $TMP
if has('directx')
set renderoptions=type:directx
endif
else
" Linux 路径 [[[3
let g:vimfiles = split(&runtimepath, ',')[0]
if exists('$VIMTMP')
let g:mytmpdir = $VIMTMP
else
let g:mytmpdir = expand("~/tmpfs")
endif
let g:MuttVim_configfile = expand('~/scripts/python/pydata/muttvim.json')
cnoremap <expr> <C-T> getcmdtype() == ':' ? '~/tmpfs/' : "\<C-t>"
" cron 的目录不要备份
set backupskip+=/etc/cron.*/*
set backupdir=.,/var/tmp,/tmp
endif
" 语言相关 [[[3
if $LANGUAGE =~ '^zh' || ($LANGUAGE == '' && v:lang =~ '^zh')
" 缓冲区号 文件名 行数 修改 帮助 只读 编码 换行符 BOM ======== 字符编码 位置 百分比位置
set statusline=%n\ %<%f\ %L行\ %{&modified?'[+]':&modifiable\|\|&ft=~'^\\vhelp\|qf$'?'':'[-]'}%h%r%{&fenc=='utf-8'\|\|&fenc==''?'':'['.&fenc.']'}%{&ff=='unix'?'':'['.&ff.']'}%{&bomb?'[BOM]':''}%{&eol?'':'[noeol]'}%{&diff?'[diff]':''}%=\ 0x%-4.8B\ \ \ \ %-14.(%l,%c%V%)\ %P
else
set statusline=%n\ %<%f\ %LL\ %{&modified?'[+]':&modifiable\|\|&ft=~'^\\vhelp\|qf$'?'':'[-]'}%h%r%{&fenc=='utf-8'\|\|&fenc==''?'':'['.&fenc.']'}%{&ff=='unix'?'':'['.&ff.']'}%{&bomb?'[BOM]':''}%{&eol?'':'[noeol]'}%{&diff?'[diff]':''}%=\ 0x%-4.8B\ \ \ \ %-14.(%l,%c%V%)\ %P
endif
" 路径相关 [[[3
let g:VEConf_favorite = g:vimfiles . "/ve_favorite"
let g:NERDTreeBookmarksFile = g:vimfiles . "/NERDTreeBookmarks"
let g:dictfilePrefix = g:vimfiles . "/dict/"
if has("python3")
exe "py3file" g:vimfiles . "/vimrc.py"
endif
if isdirectory(expand("/run/user/$UID"))
let g:undodir = expand("/run/user/$UID/vimundo")
else
let g:undodir = g:mytmpdir . "/.vimundo"
endif
let &errorfile = g:mytmpdir . "/.error"
" 图形与终端 [[[2
let g:colors_name = 'lilypink'
let &t_EI = "\e[2 q"
let &t_SI = "\e[6 q"
let &t_SR = "\e[4 q"
if has("gui_running")
set mousemodel=popup
" 有些终端不能改变大小
set columns=88
set lines=38
set cursorline
elseif has("unix")
set ambiwidth=single
if $COLORTERM == 'truecolor'
set cursorline
set termguicolors
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
elseif &term =~ '256color\|nvim'
set cursorline
else
" 在Linux文本终端下非插入模式显示块状光标
if &term == "linux" || &term == "fbterm"
exec "set t_ve+=\033[?6c"
autocmd InsertEnter * exec "set t_ve-=\033[?6c"
autocmd InsertLeave * exec "set t_ve+=\033[?6c"
" autocmd VimLeave * exec "set t_ve-=\033[?6c"
endif
if &term == "fbterm"
set cursorline
elseif $TERMCAP =~ 'Co#256'
set t_Co=256
set cursorline
else
" 暂时只有这个配色比较适合了
let g:colors_name = 'default'
endif
endif
elseif has('win32') && exists('$CONEMUBUILD')
" enable 256 colors in ConEmu on Win
set term=xterm
set t_Co=256
let &t_AB="\e[48;5;%dm"
let &t_AF="\e[38;5;%dm"
set cursorline
endif
exe "colorscheme" g:colors_name
" bracketed paste mode support for tmux
if &term =~ '^screen\|^tmux' && exists('&t_BE')
let &t_BE = "\033[?2004h"
let &t_BD = "\033[?2004l"
" t_PS and t_PE are key code options and they are special
exec "set t_PS=\033[200~"
exec "set t_PE=\033[201~"
endif
if &term =~ '^screen\|^tmux'
" This may leave mouse in use by terminal application
" exec "set t_RV=\033Ptmux;\033\033[>c\033\\"
set ttymouse=sgr
if &t_GP == ''
" for getwinpos
exec "set t_GP=\033Ptmux;\033\033[13t\033\\"
endif
" Enable modified arrow keys, see :help arrow_modifiers
execute "silent! set <xUp>=\<Esc>[@;*A"
execute "silent! set <xDown>=\<Esc>[@;*B"
execute "silent! set <xRight>=\<Esc>[@;*C"
execute "silent! set <xLeft>=\<Esc>[@;*D"
endif
" 不同的 Vim 版本 [[[2
if has("conceal")
" 'i' is for neosnippet
set concealcursor=nci
" XXX: This will cause a redraw on startup
set conceallevel=0
endif
if has("persistent_undo")
let &undodir=g:undodir
if !isdirectory(&undodir)
call mkdir(&undodir, 'p', 0700)
endif
set undofile
endif
unlet g:undodir
let g:silent_unsupported = 1
" map 相关[[[1
" nmap [[[2
" Fx 相关 [[[3
" buffer list
nmap <F2> <Leader>be
nmap <F4> :ls<CR>:buffer<Space>
nmap <F6> :cnext<CR>
nmap <S-F6> :cprevious<CR>
nmap <silent> <F9> :enew<CR>
nmap <F11> :next<CR>
nmap <S-F11> :previous<CR>
" 重新载入当前文件
nmap <F5> :e!<CR>
" t 开头 [[[3
nmap <silent> tt :tabnew<CR>
nmap <silent> TT :call Lilydjwg_copy_to_newtab()<CR>
nmap t= :call Lilydjwg_formatall()<CR>
" select all
nmap ta ggVG
nmap <silent> tf :call Lilydjwg_open_url()<CR>
" less style 清除高亮
nmap <silent> <M-u> :nohls<CR>
" join line without space
nmap tj Jx
" select line content
nnoremap tl ^vg_
nmap <silent> to :call append('.', '')<CR>j
nmap <silent> tO :call append(line('.')-1, '')<CR>k
nmap tp "+P
nmap <silent> tv :call Lilydjwg_toggle_ve()<CR>
nmap tw :call Lilydjwg_toggle_ambiwidth()<CR>
" w 开头 [[[3
nmap wc :set cursorline!<CR>
nnoremap <silent> wf :call Lilydjwg_NERDTreeOpen()<CR>
nnoremap <silent> wn :call Lilydjwg_toggle_number()<CR>
nnoremap <silent> wt :TlistToggle<CR>
nnoremap <silent> wb :TagbarToggle<CR>
" - 开头 [[[3
nmap -+ :set nomodified<CR>
nmap -c :call Lilydjwg_toggle_color()<CR>
nmap -ft :exe 'tabe '.g:vimfiles.'/ftplugin/'.&ft.'.vim'<CR>
nmap -syn :exe 'tabe '.g:vimfiles.'/syntax/'.&ft.'.vim'<CR>
nmap -int :exe 'tabe '.g:vimfiles.'/indent/'.&ft.'.vim'<CR>
" 显示高亮组 [[[4
nnoremap <silent> wh :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
" Alt 组合键 [[[3
nmap <M-m> :MRU<Space>
" 打开草稿
nmap <unique> <silent> <M-s> <Plug>ShowScratchBuffer
for i in range(1, 8)
exec 'nnoremap <silent> <M-' . i . '> '. i .'gt'
endfor
nnoremap <silent> <M-9> :exec "normal!" min([tabpagenr('$'),9])."gt"<CR>
" lusty-explorer [[[4
nmap <M-b> :LustyBufferExplorer<CR>
nmap <M-g> :LustyBufferGrep<CR>
nmap <M-l> :LustyFilesystemExplorerFromHere<CR>
let g:LustyExplorerSuppressRubyWarning = 1
" 其它开头的 [[[3
nmap <BS> <C-O>
nmap <C-D> <C-W>q
nnoremap <Space> za
nmap ' <C-W>
nmap Y y$
nmap 'm :MarksBrowser<CR>
nmap :: :!
nmap cd :lcd %:p:h<CR>:echo expand('%:p:h')<CR>
nmap gb :setl fenc=gb18030<CR>
nmap d<CR> :%s/\r//eg<CR>``
nmap cac :call Lilydjwg_changeColor()<CR>
nmap gl :IndentGuidesToggle<CR>
nnoremap <silent> gs :echo Lilydjwg_getfsize(expand('%'))<CR>
" imap [[[2
inoremap <M-c> <C-R>=Lilydjwg_colorpicker()<CR>
inoremap <C-J> <C-P>
inoremap <M-j> <C-N>
inoremap <M-q> <C-R>=Lilydjwg_qw()<CR>
imap <S-BS> <C-W>
cmap <S-BS> <C-W>
" 日期和时间 [[[3
imap <silent> <F5> <C-R>=Lilydjwg_zh_date()<CR>
imap <silent> <S-F5> <C-R>=strftime("%Y-%m-%d")<CR>
imap <silent> <C-F5> <C-R>=strftime("%Y-%m-%d %H:%M")<CR>
" 补全 [[[3
imap <F2> <C-X><C-O>
imap <F3> <C-X><C-F>
imap <S-F3> <C-X><C-L>
imap <F7> <C-R>=Lilydjwg_dictcomplete()<CR>
" 补全最长项
inoremap <expr> <C-L> pumvisible()?"\<C-E>\<C-N>":"\<C-N>"
" vmap [[[2
vnoremap <Leader># "9y?<C-R>='\V'.substitute(escape(@9,'\?'),'\n','\\n','g')<CR><CR>
vnoremap <Leader>* "9y/<C-R>='\V'.substitute(escape(@9,'\/'),'\n','\\n','g')<CR><CR>
vnoremap <C-C> "+y
" 中文引号 [[[3
vmap “ <ESC>`<i“<ESC>`>a”<ESC>
vmap ” <ESC>`>a”<ESC>`<i“<ESC>
" cmap [[[2
" 还是这样吧
" FIXME 但这样在 wildmenu 补全时会有点奇怪
cmap <C-P> <Up>
cmap <C-N> <Down>
cnoremap <Left> <Space><BS><Left>
cnoremap <Right> <Space><BS><Right>
" g[jk] [[[2
nmap <M-j> gj
nmap <M-k> gk
vmap <M-j> gj
vmap <M-k> gk
" 以 % 表示的字符 [[[2
vmap <silent> t% :w !ascii2uni -a J -q<CR>
nmap <silent> t% :call Lilydjwg_hexchar()<CR>
" HTML 转义 [[[2
" I got the idea from unimpaired.vim
noremap <silent> [x :HTMLEscape<CR>
noremap <silent> ]x :HTMLUnescape<CR>
nnoremap <silent> [x :.HTMLEscape<CR>
nnoremap <silent> ]x :.HTMLUnescape<CR>
" Ctrl-S 保存文件 [[[2
nmap <silent> <C-S> :update<CR>
imap <silent> <C-S> <ESC>:update<CR>
vmap <silent> <C-S> <ESC>:update<CR>
" 快速隐藏当前窗口内容[[[2
nmap <F12> :tabnew<CR>
imap <F12> <ESC>:tabnew<CR>
vmap <F12> <ESC>:tabnew<CR>
" mouse mapping[[[2
map <S-ScrollWheelDown> <ScrollWheelRight>
map <S-ScrollWheelUp> <ScrollWheelLeft>
imap <S-ScrollWheelDown> <ScrollWheelRight>
imap <S-ScrollWheelUp> <ScrollWheelLeft>
nnoremap <silent> <S-MiddleMouse> <LeftMouse>"+P
inoremap <silent> <S-MiddleMouse> <C-r>+
" 上下移动一行文字[[[2
nmap <C-j> :m+<cr>
nmap <C-k> :m-2<cr>
vmap <C-j> :m'>+<cr>gv
vmap <C-k> :m'<-2<cr>gv
" 自动命令[[[1
" 自动关闭预览窗口(不能用在命令窗口,所以设置了一个变量)
let s:cmdwin = 0
autocmd CmdwinEnter * let s:cmdwin = 1
autocmd CmdwinLeave * let s:cmdwin = 0
autocmd InsertLeave * if s:cmdwin == 0 && pumvisible() == 0|pclose|endif
" 插入模式下长时间不动则打断撒消序列
if (v:version == 800 && has("patch1407")) || v:version != 800
autocmd CursorHoldI * call feedkeys("\<C-g>u", 'nt')
endif
autocmd BufReadCmd *.maff,*.xmind,*.crx,*.apk,*.whl,*.egg call zip#Browse(expand("<amatch>"))
" 见 ft-syntax-omni
if has("autocmd") && exists("+omnifunc")
autocmd Filetype *
\ if &omnifunc == "" && !get(b:, 'disable_omnifunc') |
\ setlocal omnifunc=syntaxcomplete#Complete |
\ endif
endif
if exists('##TerminalWinOpen')
autocmd TerminalWinOpen * setlocal nonumber
endif
" don't show q: hints
augroup vimHints | exe 'au!' | augroup END
" 自定义命令[[[1
" 对齐 xxx: xxx (两栏)
" .vimrc 有可能是软链接
exe 'command Set tabe ' . escape(resolve($MYVIMRC), ' ')
" 删除当前文件
command Delete if delete(expand('%')) | echohl WarningMsg | echo "删除当前文件失败" | echohl None | endif
command -nargs=1 -range=% -bang Join <line1>,<line2>call Lilydjwg_join(<q-args>, "<bang>")
command -nargs=+ Reindent call Lilydjwg_reindent(<f-args>)
" TODO better implement
command -range=% ClsXML <line1>,<line2>!tidy -utf8 -iq -xml
command -range=% ClsHTML <line1>,<line2>!tidy -utf8 -iq -omit -w 0
command -range=% ClsJSON setf json | <line1>,<line2>!jq .
command -nargs=1 -complete=customlist,Lilydjwg_complete_So So runtime so/<args>.vim
command -nargs=1 Delmark delm <args>|wviminfo!
" 删除空行
command -range=% -bar DBlank <line1>,<line2>g/^\s*$/d_|nohls
" 某个 pattern 出现的次数
command -range=% -nargs=1 Count <line1>,<line2>s/<args>//gn|nohls
command -range=% -bar SBlank <line1>,<line2>s/\v(^\s*$\n){2,}/\r/g
" 删除拖尾的空白
command -range=% -bar TWS <line1>,<line2>s/\s\+$//|nohls|normal ``
" 设置成 Linux 下适用的格式
command Lin setl ff=unix fenc=utf8 nobomb eol
" 设置成 Windows 下适用的格式
command Win setl ff=dos fenc=gb18030
" 以第一行的文字为名保存当前文件
command TSave call Lilydjwg_TSave()
command -nargs=? -complete=file RSplit vs <args>|normal <C-W>L<C-W>w
command -range=% -bar SQuote <line1>,<line2>s/“\|”\|″/"/ge|<line1>,<line2>s/‘\|’\|′/'/ge
command -range -bar HTMLEscape <line1>,<line2>s/&/\&/ge|<line1>,<line2>s/</\</ge|<line1>,<line2>s/>/\>/ge
command -range -bar HTMLUnescape <line1>,<line2>s/&/\&/ge|<line1>,<line2>s/</</ge|<line1>,<line2>s/>/>/ge
" 用 VimExplorer 插件打开当前文件所在的目录
command Path VE %:p:h
command -nargs=1 Enc e ++bad=keep ++enc=<args> %
command CenterFull call CenterFull()
command -nargs=1 -range=% -complete=customlist,Lilydjwg_Align_complete LA <line1>,<line2>call Lilydjwg_Align("<args>")
command -nargs=1 -range=% Column <line1>,<line2>Align! w<args>0P1p \S\@<=\s\@=
command -range=% Paste <line1>,<line2>py3 LilyPaste()
command -range=% Tohtml call Lilydjwg_to_html(<line1>, <line2>)
command BufClean call Lilydjwg_cleanbufs()
command Helptags for d in filter(globpath(&rtp, "doc/", 0, 1), 'filewritable(v:val)') | exec "helptags" d | endfor
" 插件配置[[[1
" ft-rust[[[2
let g:rust_fold = 1
" asyncrun.vim[[[2
command! -bang -nargs=* -complete=file Make AsyncRun -program=make @ <args>
" choosewin[[[2
nmap <M-w> <Plug>(choosewin)
let g:choosewin_overlay_enable = 1
let g:choosewin_statusline_replace = 0
" linediff[[[2
let g:linediff_buffer_type = 'scratch'
" rst_tables[[[2
let g:rst_tables_no_warning = 1
" signify [[[2
let g:signify_vcs_list = ['git']
let g:signify_sign_overwrite = 0
" signify won't update on FocusGained anymore
let g:signify_disable_by_default = 1
" ConflictMotions [[[2
" 禁用 \x 开头的映射;它们与 EnhancedCommentify 冲突了
let g:ConflictMotions_TakeMappingPrefix = ''
" NrrRgn[[[2
let g:nrrw_rgn_vert = 1
let g:nrrw_rgn_wdth = 80
let g:nrrw_rgn_hl = 'Folded'
" cycle[[[2
" https://github.com/lilydjwg/vim-cycle
nnoremap <expr> <silent> <C-X> Lilydjwg_trycycle('x')
vnoremap <expr> <silent> <C-X> Lilydjwg_trycycle('x')
nnoremap <expr> <silent> <C-A> Lilydjwg_trycycle('p')
vnoremap <expr> <silent> <C-A> Lilydjwg_trycycle('p')
nnoremap <Plug>CycleFallbackNext <C-A>
nnoremap <Plug>CycleFallbackPrev <C-X>
let g:cycle_no_mappings = 1
let g:cycle_default_groups = [
\ [['true', 'false']],
\ [['yes', 'no']],
\ [['and', 'or']],
\ [['on', 'off']],
\ [['>', '<']],
\ [['==', '!=']],
\ [['是', '否']],
\ [['有', '无']],
\ [["in", "out"]],
\ [["min", "max"]],
\ [["get", "post"]],
\ [["to", "from"]],
\ [["read", "write"]],
\ [['with', 'without']],
\ [["exclude", "include"]],
\ [["asc", "desc"]],
\ [["next", "prev"]],
\ [["encode", "decode"]],
\ [["left", "right"]],
\ [["hide", "show"]],
\ [['「:」', '『:』'], 'sub_pairs'],
\ [['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday',
\ 'Friday', 'Saturday'], 'hard_case', {'name': 'Days'}],
\ [["enable", "disable"]],
\ [["add", "remove"]],
\ [['up', 'down']],
\ [['after', 'before']],
\ ]
" Erlang[[[2
let g:erlangHighlightBif = 1
let g:erlangFold = 1
" grep.vim[[[2
let g:Grep_Default_Options = '--binary-files=without-match'
" NERDTree[[[2
let g:NERDTreeMapToggleZoom = 'a'
let g:NERDTreeMapToggleHidden = 'h'
" 另见平台相关部分
" bufexplorer[[[2
let g:bufExplorerFindActive = 0
" tagbar[[[2
let g:tagbar_type_dosini = {
\ 'ctagstype': 'ini',
\ 'kinds': ['s:sections', 'b:blocks'],
\ }
let g:tagbar_type_pgsql = {
\ 'ctagstype': 'pgsql',
\ 'kinds': ['f:functions', 't:tables'],
\ }
" taglist[[[2
let Tlist_Show_One_File = 1
let tlist_vimwiki_settings = 'wiki;h:headers'
let tlist_tex_settings = 'latex;h:headers'
let tlist_tracwiki_settings = 'wiki;h:headers'
let tlist_diff_settings = 'diff;m:modified;n:created;d:deleted;h:hunks'
let tlist_git_settings = 'diff;m:modified;n:created;d:deleted;h:hunks'
let tlist_gitcommit_settings = 'gitcommit;f:file'
let tlist_privoxy_settings = 'privoxy;s:sections'
" 来源 http://gist.github.com/476387
let tlist_html_settings = 'html;h:Headers;o:IDs;c:Classes'
let tlist_dosini_settings = 'ini;s:sections'
let tlist_pgsql_settings = 'pgsql;f:functions;t:tables'
let tlist_markdown_settings = 'markdown;h:headers'
let tlist_rust_settings = 'rust;n:modules;s:structural types;i:trait interfaces;c:implementations;f:functions;g:enums;t:type aliases;v:global variables;M:macro definitions;m:struct fields;e:enum variants;F:methods'
hi link MyTagListFileName Type
" 2html.vim, 使用XHTML格式[[[2
let use_xhtml = 1
" shell 脚本打开折叠
let g:sh_fold_enabled = 3 " 打开函数和 here 文档的折叠
" Align[[[2
let g:Align_xstrlen = 4 " use strdisplaywidth
" Lilydjwg_Align
" Meanings:
" colon: dict definition like 'key: value,'
" colonl: list items like this one
" comment: #-style comments
" jscomment: //-style comments
let g:Myalign_def = {
\ 'colon': ['WP0p1l:', ':\@<=', 'g ,'],
\ 'colonl': ['WP0p1l:', ':\@<='],
\ 'comma': ['WP0p1l:', ',\@<=', 'g ,'],
\ 'commalist': ['WP0p1l', ',\@<=', 'g ,'],
\ 'comment': ['WP1p1l:', '#'],
\ 'css': ['WP0p1l:', ':\@<=', 'v \v^\s*/\*|\{|\}'],
\ 'define': ['WP0p1l:', ' \d\@=', 'g ^#define\s'],
\ 'jscomment': ['WP0p1l:', '//'],
\ }
" EnhancedCommentify[[[2
let g:EnhCommentifyRespectIndent = 'Yes'
let g:EnhCommentifyUseSyntax = 'Yes'
let g:EnhCommentifyPretty = 'Yes'
let g:EnhCommentifyBindInInsert = 'No'
let g:EnhCommentifyMultiPartBlocks = 'Yes'
let g:EnhCommentifyCommentsOp = 'Yes'
let g:EnhCommentifyAlignRight = 'Yes'
let g:EnhCommentifyUseBlockIndent = 'Yes'
" indent/html.vim[[[2
let g:html_indent_inctags = "html,body,head,tbody,p,li,dd,marquee,header,nav,article,section"
let g:html_indent_script1 = "inc"
let g:html_indent_style1 = "inc"
" mru[[[2
let MRU_File = g:vimfiles . '/vim_mru_files'
let MRU_Max_Entries = 2000
let MRU_Exclude_Files = '\v^.*\~$|/COMMIT_EDITMSG$|/itsalltext/|^/tmp/'
" 加载菜单太耗时
let MRU_Add_Menu = 0
let MRU_Filename_Format = {
\ 'formatter': 'v:val',
\ 'parser': '.*',
\ 'syntax': '[^/]\+$'
\ }
" syntax/haskell.vim[[[2
let hs_highlight_boolean = 1
let hs_highlight_types = 1
let hs_highlight_more_types = 1
" syntax/python.vim[[[2
let python_highlight_all = 1
" syntax/vim.vim 默认会高亮 s:[a-z] 这样的函数名为错误[[[2
let g:vimsyn_noerror = 1