/
_vimrc
830 lines (693 loc) · 27.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
" yyq's vimrc
" Initialization... {{{
if has('autocmd')
" Remove ALL autocommands for the current group
au!
endif
set nocompatible "disable backwards-compatible with vi
filetype off
set viminfo=<100,'100,/50,:100,h,r$TEMP:,s10
" | | | | | | + 不保存超过10KB寄存器
" | | | | | + 不保存TEMP目录下文件的相关信息
" | | | | + 载入viminfo文件时关闭hlsearch高亮
" | | | + 保存命令历史条数
" | | + 保存搜索历史条数
" | + 保存最近100个文件中的标记
" + 每个寄存器中保存的行数
"set selection=inclusive
" }}}
" General {{{
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin
if has('win32') || has ('win64')
let $VIMFILES = '""' . $VIM . '\vimfiles"'
else
let $VIMFILES = $HOME."/.vim"
endif
set t_Co=256
set background=dark
set path+=./**
set backup " make backup files
set backupdir=C:\Temp " where to put backup files
set backupskip=C:\Temp " Don’t create backups when editing files in certain directories
set noswapfile " no swap files
set undofile " make undo files
set undodir=C:\Temp
set undolevels=1000 " use many muchos levels of undo
set history=1000 " remember more commands and<LeftMouse> search history
set ignorecase " ignore case when searching
set infercase " ignore case whet auto-complete
set smartcase " ignore case if search pattern is all lowercase, case-sensitive otherwise
set smarttab " insert tabs on the start of a line according to shiftwidth, not tabstop
set backspace=indent,eol,start " allow backspacing over everything in insert mode
set confirm " Show confirm dialog
set autoindent " always set autoindenting on
set copyindent " copy the previous indentation on autoindenting
set showmatch " set show matching parenthesis
set incsearch " show search matches as you type
set visualbell " Silence the bell, use a flash instead
set showcmd " Show (partial) command in status line
set showmode " Show the current mode
set wildmenu " turn on command line completion wild style
set wildmode=list:longest,full
set wildignore=*.dll,*.exe,*.gif,*.jpg,*.mm ",*.png,*.snag,*.ssd,*.xmind
set esckeys " Allow cursor keys in insert mode
set modeline " Respect modeline in files
set modelines=4
set report=0 " Always display message
set shortmess-=S "display number of search matches & index of a current match
set dictionary=D:\cygwin64\usr\share\dict\linux.words
set thesaurus=$HOME\vimfiles\thesaurus\english.txt
"set gdefault " applies substitutions globally on lines
" }}}
" Shell {{{
"set shell=$COMSPEC " sets shell to correct path for cmd.exe
" Makes bash open in the working directory
"let $CHERE_INVOKING=1
" Default path for Cygwin 64-bit, change accordingly
"set shell=D:\cygwin64\bin\bash.exe
" Without --login, Cygwin won't mount some directories such as /usr/bin/
"set shellcmdflag=--login\ -c
" Default value is (, but bash needs "
set shellxquote=\"
" Paths will use / instead of \
"set shellslash
" PATH to determine available checkers
"let $PATH .= ';D:\cygwin64\bin'
" }}}
" Lines {{{
"set whichwrap=b,s,h,l,<,>,~,[,] " everything wraps
" | | | | | | | | |
" | | | | | | | | +-- "]" Insert and Replace
" | | | | | | | +-- "[" Insert and Replace
" | | | | | | +-- "~" Normal
" | | | | | +-- <Right> Normal and Visual
" | | | | +-- <Left> Normal and Visual
" | | | +-- "l" Normal and Visual (not recommended)
" | | +-- "h" Normal and Visual (not recommended)
" | +-- <Space> Normal and Visual
" +-- <BS> Normal and Visual
" don't wrap lines
set wrap
map <F2> <Esc>:set wrap!<CR>
"map <S-F2> <Esc>:set wrap<CR>
" Makes gj/gk move by virtual lines when used without a count, and by physical lines when used with a count.
noremap <silent> <expr> j (v:count == 0 ? 'gj' : 'j')
noremap <silent> <expr> k (v:count == 0 ? 'gk' : 'k')
" Like gJ, but always remove spaces
fun! JoinSpaceless()
execute 'normal gJ'
" Character under cursor is whitespace?
if matchstr(getline('.'), '\%' . col('.') . 'c.') =~ '\s'
" When remove it!
execute 'normal dw'
endif
endfun
nnoremap <F10> :call JoinSpaceless()<CR>
" }}}
" Paste {{{
" Vim will switch to paste mode, disabling all kinds of smartness and
" just pasting a whole buffer of text.
" When in paste-mode auto indent will be turned off.
set pastetoggle=<F5>
set paste
" Use the OS clipboard by default
set clipboard=unnamed
" }}}
" UI {{{
" highlight the current column&line
set cursorline cursorcolumn
highlight Cursor guifg=white guibg=#1874cd
highlight iCursor guifg=white guibg=#1874cd
"highlight CursorLine guibg=white
" set the menu & the message to English
set langmenu=en_US
let $LANG = 'en_US'
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
"language message zh_CN.UTF-8
language message en_US.UTF-8
set number
" set relativenumber
hi CursorLineNr guifg=silver
set mouse=a " enable full mouse support in the console
autocmd GUIEnter * simalt ~x " 启动时最大化
set ruler " Always show current positions along the bottom
"}}}
" Menus {{{
amenu <silent>Tabs.New<TAB>Open\ a\ new\ tab :tabnew<CR>
amenu Tabs.-SEPT1- :
amenu <silent>Tabs.&Next :tabnext<CR>
amenu <silent>Tabs.&Previous :tabprevious<CR>
amenu Tabs.-SEPT2- :
amenu Tabs.&Close :confirm tabclose<CR>
"}}}
" ToolBar {{{
" Do not install the ToolBar if it is already done.
"if !exists("did_install_custom_toolbar")
" let did_install_custom_toolbar = 1
amenu 1.10 ToolBar.New :new<CR>
amenu 1.20 ToolBar.Open :browse confirm e<CR>
" an <silent> icon=~/.gvim/bitmaps/16/document-save.png 1.30 ToolBar.Save :if expand("%") == ""<Bar>browse confirm w<Bar>else<Bar>confirm w<Bar>endif<CR>
" an icon=~/.gvim/bitmaps/16/system-floppy.png 1.40 ToolBar.SaveAll :browse confirm wa<cr>
" an 1.45 ToolBar.-sep1- <Nop>
" an icon=$VIMFILES/bitmaps/16/edit-undo.png 1.50 ToolBar.Undo u
" an icon=$VIMFILES/bitmaps/16/edit-redo.png 1.60 ToolBar.Redo <C-R>
" an 1.65 ToolBar.-sep2- <Nop>
" vnoremenu icon=~/.gvim/bitmaps/16/edit-cut.png 1.70 ToolBar.Cut "+x
" vnoremenu icon=~/.gvim/bitmaps/16/edit-copy.png 1.80 ToolBar.Copy "+y
" cnoremenu icon=~/.gvim/bitmaps/16/edit-copy.png 1.80 ToolBar.Copy <C-Y>
" nnoremenu icon=~/.gvim/bitmaps/16/edit-paste.png 1.90 ToolBar.Paste "+gP
" cnoremenu icon=~/.gvim/bitmaps/16/edit-paste.png ToolBar.Paste <C-R>+
" exe 'vnoremenu <script> ToolBar.Paste ' . paste#paste_cmd['v']
" exe 'inoremenu <script> ToolBar.Paste ' . paste#paste_cmd['i']
aunmenu ToolBar.-sep6-
aunmenu ToolBar.Make
aunmenu ToolBar.RunCtags
aunmenu ToolBar.TagJump
an 1.400 ToolBar.-sep8- <Nop>
"an icon=~/.gvim/bitmaps/16/preferences-system-windows.png 1.300 ToolBar.MiniBufExplorer :TMiniBufExplorer<CR>
an icon=WinMax 1.410 ToolBar.Maximize <C-w>_
an icon=WinVSplit 1.420 ToolBar.ResizeEqual <C-w>=
"an icon=~/.gvim/bitmaps/16/stock_spellcheck.png 1.130 ToolBar.Syntastic :SyntasticCheck<CR>
"an icon=~/.gvim/bitmaps/16/document-revert.png 1.140 ToolBar.Alternate :A<CR>
"an 1.195 ToolBar.-sep4- <Nop>
"an icon=~/.gvim/bitmaps/16/accessories-dictionary.png 1.200 ToolBar.Tagbar :TagbarToggle<CR>
"if version >= 703
" an 1.210 ToolBar.Undotree :UndotreeToggle<CR>
"endif
"an icon=~/.gvim/bitmaps/16/system-file-manager.png 1.220 ToolBar.FileExplorer :NERDTreeToggle<CR>
"an 1.395 ToolBar.-sep6- <Nop>
"if version >= 703
" an icon=~/.gvim/bitmaps/16/applications-engineering.png 1.400 ToolBar.Numbers :NumbersToggle<CR>
"endif
"nmenu icon=~/.gvim/bitmaps/16/format-text-direction-ltr.png 1.410 ToolBar.Comment gcc
"vmenu icon=~/.gvim/bitmaps/16/format-text-direction-ltr.png 1.410 ToolBar.Comment gc
"imenu icon=~/.gvim/bitmaps/16/format-text-direction-ltr.png 1.410 ToolBar.Comment <C-O>gcc
"nmenu icon=~/.gvim/bitmaps/16/format-indent-more.png 1.420 ToolBar.IndentMore >>
"vmenu icon=~/.gvim/bitmaps/16/format-indent-more.png 1.420 ToolBar.IndentMore >
"imenu icon=~/.gvim/bitmaps/16/format-indent-more.png 1.420 ToolBar.IndentMore <C-O>>>
"nmenu icon=~/.gvim/bitmaps/16/format-indent-less.png 1.430 ToolBar.IndentLess <<
"vmenu icon=~/.gvim/bitmaps/16/format-indent-less.png 1.430 ToolBar.IndentLess <
"imenu icon=~/.gvim/bitmaps/16/format-indent-less.png 1.430 ToolBar.IndentLess <C-O><<
"if !has("gui_athena")
" an 1.895 ToolBar.-sep7- <Nop>
" an icon=~/.gvim/bitmaps/16/edit-find-replace.png 1.900 ToolBar.Replace :promptrepl<CR>
" vunmenu ToolBar.Replace
" vnoremenu icon=~/.gvim/bitmaps/16/edit-find-replace.png ToolBar.Replace y:promptrepl <C-R>=<SID>FixFText()<CR><CR>
" an icon=~/.gvim/bitmaps/16/go-next.png 1.910 ToolBar.FindNext n
" an icon=~/.gvim/bitmaps/16/go-previous.png 1.920 ToolBar.FindPrev N
" endif
"}}}
" ToolTips {{{
tmenu 1.10 ToolBar.New New
tmenu 1.20 ToolBar.Open Open
tmenu 1.30 ToolBar.Save Save
tmenu 1.40 ToolBar.SaveAll Save All
tmenu 1.50 ToolBar.Print Print
tmenu 1.60 ToolBar.Undo Undo
tmenu 1.70 ToolBar.Redo Redo
tmenu 1.80 ToolBar.Cut Cut
tmenu 1.90 ToolBar.Copy Copy
tmenu 1.100 ToolBar.Paste Paste
tmenu ToolBar.RunScript Run Script
tmenu ToolBar.Help Help
tmenu ToolBar.FindHelp Find Help
"tmenu 1.200 ToolBar.Tagbar Afficher les tags
"if version >= 703
" tmenu 1.210 ToolBar.Undotree Afficher l'historique d'édition
"endif
"tmenu 1.300 ToolBar.MiniBufExplorer Afficher le mini explorateur de tampons
tmenu 1.310 ToolBar.Maximize Maximize Buffer
tmenu 1.320 ToolBar.ResizeEqual Resize Equal Buffer
if version >= 703
tmenu 1.400 ToolBar.Numbers Alterner entre affichage classique et relatif des numéros de lignes
endif
tmenu 1.410 ToolBar.Comment Commenter
tmenu 1.420 ToolBar.IndentMore Indenter
tmenu 1.430 ToolBar.IndentLess Désindenter
if !has("gui_athena")
tmenu 1.900 ToolBar.Replace Replace
tmenu 1.910 ToolBar.FindNext Find Nex
tmenu 1.920 ToolBar.FindPrev Find Previous
endif
"}}}
" File {{{
set fileencoding=utf-8
set encoding=utf-8
set tenc=utf-8
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
set autoread "error alert for destructive write
"print the current clock time
"set printheader=%<%f%h%m%40{strftime(\"%I:%M:%S\ \%p,\ %a\ %b\ %d,\ %Y\")}%=Page\ %N
"Print the last modification time
"set printheader=%<%f%h%m\ %40{strftime(\"%c\",getftime(expand(\"%%\")))}%=Page\ %N
"Turning on options for filetypes; detection, plugins, and indentation
filetype plugin on
if has("autocmd") && exists("+omnifunc")
autocmd Filetype *
\ if &omnifunc == "" |
\ setlocal omnifunc=syntaxcomplete#Complete |
\ endif
endif
" using vimdiff from within vim
au FilterWritePre * if &diff | colorscheme default | endif
" calling vimdiff from the command-line
if &diff
colorscheme default
else
colorscheme Tomorrow-Night "xoria256
endif
" }}}
" statusline {{{
set laststatus=2 "enable status line always
set statusline=%2*%n%m%r%h%w%*\ %F\ %1*[FORMAT=%2*%{&ff}:%{&fenc!=''?&fenc:&enc}%1*]\ [TYPE=%2*%Y%1*]\ [COL=%2*%03v%1*]\ [ROW=%2*%03l%1*/%3*%L(%p%%)%1*]
function! InsertStatuslineColor(mode)
if a:mode == 'i'
hi statusline guibg=peru
elseif a:mode == 'r'
hi statusline guibg=blue
else
hi statusline guibg=#1C1C1C
endif
endfunction
au InsertEnter * call InsertStatuslineColor(v:insertmode)
au InsertLeave * hi statusline guibg=#1C1C1C guifg=white
hi statusline guibg=#1C1C1C
hi User1 guifg=gray
hi User2 guifg=peru
hi User3 guifg=white
hi User4 gui=bold
" }}}
" Font {{{
if has('gui_running')
" 确保所有的文件类型会在菜单“语法”(“Syntax”)下出现,而不是出现一个菜单项“Show filetypes in menu”
"let do_syntax_sel_menu=1
set guioptions-=m
set guioptions-=T
set guioptions-=r
set guioptions-=l
set guioptions-=b
if has("win16") || has("win32") || has("win95") || has("win64")
set guifont=Sarasa\ Mono\ SC:h11,SpaceMono\ NF:h11,Inconsolata:h12,Consolas:h11,Courier_New:h11:cANSI
"set guifontwide=Sarasa\ Mono\ SC:h11
else
set guifont=MiscFixed\ Semi-Condensed\ 10
endif
endif
" }}}
" Maps {{{
" Alternate open/close a fold
nnoremap <space> za
"nmap <tab> V>
"nmap <s-tab> V<
"vmap <tab> >gv
"vmap <s-tab> <gv
" Stay in visual mode when indenting.
vnoremap < <gv
vnoremap > >gv
nnoremap <C-Insert> :tabnew<CR>
nnoremap <C-Delete> :tabclose<CR>
noremap <silent><tab>m :tabnew<cr>
noremap <silent><tab>e :tabclose<cr>
noremap <silent><tab>n :tabn<cr>
noremap <silent><tab>p :tabp<cr>
noremap <silent><s-tab> :tabnext<CR>
inoremap <silent><s-tab> <ESC>:tabnext<CR>
" Search for visually highlighted text
vmap <silent> // y/<C-R>=escape(@", '\\/.*$^~[]')<CR><CR>
" Open help on current word in a new tab
noremap <silent> <F1> :execute "tab h " . expand("<cword>")<cr>
" Alternate open/close menu/toolbar
nnoremap <C-F1> :if &go=~#'m'<Bar>set go-=m<Bar>else<Bar>set go+=m<Bar>endif<CR>
nnoremap <C-F2> :if &go=~#'T'<Bar>set go-=T<Bar>else<Bar>set go+=T<Bar>endif<CR>
nnoremap <C-F3> :if &go=~#'r'<Bar>set go-=r<Bar>else<Bar>set go+=r<Bar>endif<CR>
nnoremap <C-F4> :if &laststatus==2<Bar>set laststatus=0<Bar>else<Bar>set laststatus=2<Bar>endif<CR>
" 显示/禁止行列光标
nmap <silent> <F6> <Esc>:call ToggleCursor()<CR>
" Determining the highlight group that the word under the cursor belongs to
nmap <silent> <F7> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
" Show all buffers in tabs, or to close all tabs (toggle: it alternately executes :tab ball and :tabo).
let notabs = 0
nnoremap <silent> <F8> :let notabs=!notabs<Bar>:if notabs<Bar>:tabo<Bar>:else<Bar>:tab ball<Bar>:tabn<Bar>:endif<CR>
function! ToggleCursor()
if &cursorcolumn
set nocursorline nocursorcolumn
else
set cursorline cursorcolumn
endif
endfunction
" clear highlighted searches
nmap <silent> ,/ :nohlsearch<CR>
function! ToggleHLSearch()
if &hls
set nohls
else
set hls
endif
endfunction
" Using very magic mode
nnoremap / /\v
vnoremap / /\v
cnoremap %s/ %s/\v
nnoremap :g/ :g/\v
set grepprg=grep\ -rnIH\ --exclude-dir=.git
let mapleader="," "Default \
nmap <silent> <leader><space> <Esc>:call ToggleHLSearch()<CR>
"Close tag
"inoremap <lt>/ </<C-x><C-o>
inoremap <C-Enter> </<C-x><C-o>
" Mark any tabs that are not at the beginning of the lines
nnoremap <leader>mt :match errorMsg /[^\t]\zs\t\+/<CR>
" Quickly edit/reload the vimrc file
nmap <silent> <leader>tv :tabe $MYVIMRC<CR>
nmap <silent> <leader>sv :so $MYVIMRC<CR>
autocmd BufWritePost $MYVIMRC source $MYVIMRC
" Reselect the text that was just pasted
nnoremap <leader>p V`]
" Open learn-vi folder
let g:browsefilter = "*.*"
nnoremap <leader>v :browse tabe E:\Anthony_GitHub\learn-vim<CR>
" 打开另存为对话框
nnoremap <leader>w :browse sav<CR>
" Set current directory to current file with ,cd
nnoremap <leader>cd :cd %:p:h<CR>:pwd<CR>
"open windows command prompt in the current file's directory
nnoremap <leader>cc :!start cmd /k cd %:p:h:8<cr>
"open explorer in the current file's directory
nnoremap <leader>ce :!start explorer %:p:h:8<cr>
" 复制当前文件/路径到剪贴板
nmap <leader>fn :let @*=substitute(expand("%"), "/", "\\", "g")<CR>
nmap <leader>fp :let @*=substitute(expand("%:p"), "/", "\\", "g")<CR>
nnoremap <leader>a <C-A>
nnoremap <leader>x <C-X>
" toggle use of 'modeline' command. Doesn't reload the
" settings until you do BufRead. vimrc doesn't support the command
" separator '|' so we use '<bar>':
" nnoremap <leader>ml :setlocal invmodeline <bar> doautocmd BufRead<cr>
" }}}
" Improve performance {{{
autocmd BufWinLeave * call clearmatches()
set nospell
" }}}
" Abbreviations {{{
" Ctrl-] is used to expand an abbreviation without inserting any extra characters
abbreviate #b /**********************
abbreviate #e **********************/
iabbrev pcode <p style="text-indent:2em"><code class="inset"></code></p><Esc>2F<i
iabbrev icode <code class="inset"></code><Esc>F<i
"iabbrev icode <code class="inset">!cursor!</code><Esc>:call search('!cursor!','b')<cr>cf!
"cabbrev h tab h
" }}}
" Others {{{
" Template
autocmd! BufNewFile * silent! 0r $VIM/vimfiles/skel/Template.%:e
" Fold
set foldenable " Turn on folding
set foldmethod=marker " Fold on the marker
set foldcolumn=2
" Show invisible characters
set list
set listchars=tab:\|.,trail:,nbsp:.,extends:¬
" Enter the middle-dot by pressing Ctrl-k then .M
" Enter the right-angle-quote by pressing Ctrl-k then >>
" Enter the Pilcrow mark by pressing Ctrl-k then PI
" The command :dig displays other digraphs you can use.
"au FocusLost * :wa "save on losing focus
" visually select text then press ~ to convert the text to UPPER CASE,
" then to lower case, then to Title Case.
function! TwiddleCase(str)
if a:str ==# toupper(a:str)
let result = tolower(a:str)
elseif a:str ==# tolower(a:str)
let result = substitute(a:str,'\(\<\w\+\>\)', '\u\1', 'g')
else
let result = toupper(a:str)
endif
return result
endfunction
vnoremap ~ y:call setreg('', TwiddleCase(@"), getregtype(''))<CR>gv""Pgvl
" Advanced Incrementing
let g:UNum=0
function! INC(increment)
let g:UNum = g:UNum + a:increment
return g:UNum
endfunction
" Delete duplicate lines
function! DelDupLine()
if getline(".") == getline(line(".") - 1)
norm dd
endif
endfunction
" }}}
" HTML {{{
" Escape/unescape & < > HTML entities in range (default current line).
function! HtmlEntities(line1, line2, action)
let search = @/
let range = 'silent ' . a:line1 . ',' . a:line2
if a:action == 0 " must convert & last
execute range . 'sno/</</eg'
execute range . 'sno/>/>/eg'
execute range . 'sno/&/&/eg'
else " must convert & first
execute range . 'sno/&/&/eg'
execute range . 'sno/</</eg'
execute range . 'sno/>/>/eg'
endif
nohl
let @/ = search
endfunction
command! -range -nargs=1 HEntities call HtmlEntities(<line1>, <line2>, <args>)
noremap <silent> <Leader>hu :HEntities 0<CR>
noremap <silent> <Leader>he :HEntities 1<CR>
map <silent> <F9> <Esc>:HEntities 1<CR>
" }}}
" Autocommand {{{
augroup filetypedetect
au BufNewFile,BufRead *.csc setfiletype csc
au BufNewFile,BufRead *.msh setfiletype mxl
au BufNewFile,BufRead *.mxl setfiletype mxl
au BufNewFile,BufRead *.rle setfiletype rle
au BufNewFile,BufRead *.log setfiletype log
augroup end
"au Filetype html,xml,xsl source $VIM/vimfile/plugin/closetag.vim
"au FileType html,xml set omnifunc=xmlcomplete#CompleteTags
augroup vimrc-auto-mkdir
autocmd!
autocmd BufWritePre * call s:auto_mkdir(expand('<afile>:p:h'), v:cmdbang)
function! s:auto_mkdir(dir, force)
if !isdirectory(a:dir)
\ && (a:force
\ || input("'" . a:dir . "' does not exist. Create? [y/N]") =~? '^y\%[es]$')
call mkdir(iconv(a:dir, &encoding, &termencoding), 'p')
endif
endfunction
augroup END
augroup vgrep
autocmd!
autocmd QuickFixCmdPost [^l]* cwindow
autocmd QuickFixCmdPost l* lwindow
augroup END
"function! UpdateTimestamp ()
" '[,']s/Last Updated: 12/23/2019 4:04:19 PM
"endfunction
"augroup TimeStamping
" autocmd!
" autocmd BufWritePre,FileWritePre,FileAppendPre * :call UpdateTimestamp()
"augroup END
" }}}
" User Defined Command {{{
command! -bar DelTab %s/ //
command! DelLF %s/\n//
command! FmtCode DelTab|DelLF
"}}}
" Source Code {{{
set pythonthreehome=C:\tools\Python3
set pythonthreedll=C:\tools\Python3\python38.dll
augroup make_python
au!
au FileType python set makeprg=C:\tools\Python3\python\ %
augroup end
"}}}
" BeforPlugin {{{
"let g:no_html_tab_mapping = 'yes'
"let g:html_map_leader = mapleader
packadd! matchit
" }}}
" Plugin Vundle {{{
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" set the runtime path to include Vundle and initialize
let $VIM="C:\\Users\\yiqyuan"
set rtp+=$VIM\vimfiles\bundle\Vundle.vim\
call vundle#begin('$VIM\vimfiles\bundle\')
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
Plugin 'lilydjwg/colorizer'
Plugin 'kshenoy/vim-signature' "toggle, display and navigate marks
Plugin 'MarcWeber/vim-addon-mw-utils' "interpret a file by function and cache file automatically
Plugin 'tomtom/tlib_vim' "Some utility functions
Plugin 'garbas/vim-snipmate'
Plugin 'honza/vim-snippets'
Plugin 'yyq123/HTML-Editor'
Plugin 'mattn/webapi-vim'
Plugin 'mbbill/fencview'
Plugin 'liuchengxu/vim-which-key'
Plugin 'machakann/vim-sandwich'
Plugin 'KabbAmine/zeavim.vim'
"Disabled plugin
"Plugin 'mattn/gist-vim'
"---------------------------------------------------
"plugin from http://vim-scripts.org/vim/scripts.html
"Plugin 'L9'
" Git plugin not hosted on GitHub
"Plugin 'https://github.com/wincent/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
"Plugin 'file:///home/gmarik/path/to/plugin'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
"Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" Install L9 and avoid a Naming conflict if you've already installed a
" different version somewhere else.
"Plugin 'ascenator/L9', {'name': 'newL9'}
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList - lists configured plugins
" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line
" }}}
" Plugin vim-signature {{{
hi SignColumn ctermbg=NONE guibg=#131313
hi SignatureMarkText ctermbg=NONE guibg=#131313 gui=bold term=bold cterm=bold
" }}}
" Plugin vim-sinpmate {{{
" Alt+Space
imap <M-space> <Plug>snipMateNextOrTrigger
smap <M-space> <Plug>snipMateNextOrTrigger
xmap <M-space> <Plug>snipMateVisual
" }}}
" Plugin Gist-vim {{{
" let github_user = 'yyq123'
" }}}
" Rainbow Parentheses Improved {{{
" let g:rainbow_active = 0 "0 if you want to enable it later via :RainbowToggle
" }}}
" Plugin Netrw {{{
if ($OS =~ "Windows")
let g:netrw_scp_cmd="pscp.exe -q"
endif
let g:netrw_liststyle = 3
let g:netrw_banner = 0
let g:netrw_winsize = 25
let g:netrw_browse_split = 4
let g:netrw_altv = 1
"augroup ProjectDrawer
"autocmd!
"autocmd VimEnter * :Vexplore
"augroup END
map <F3> <Esc>:Vex<CR>
" }}}
" Plugin vim-sandwich {{{
nmap s <Nop>
xmap s <Nop>
"xunmap S
"runtime macros/sandwich/keymap/surround.vim
nmap srt <Plug>(operator-sandwich-replace)<Plug>(textobj-sandwich-query-a)tt
" if you have not copied default recipes
let g:sandwich#recipes = deepcopy(g:sandwich#default_recipes)
" add spaces inside bracket
let g:sandwich#recipes += [
\ {'buns': ['{ ', ' }'], 'nesting': 1, 'match_syntax': 1, 'kind': ['add', 'replace'], 'action': ['add'], 'input': ['{']},
\ {'buns': ['[ ', ' ]'], 'nesting': 1, 'match_syntax': 1, 'kind': ['add', 'replace'], 'action': ['add'], 'input': ['[']},
\ {'buns': ['( ', ' )'], 'nesting': 1, 'match_syntax': 1, 'kind': ['add', 'replace'], 'action': ['add'], 'input': ['(']},
\ {'buns': ['{\s*', '\s*}'], 'nesting': 1, 'regex': 1, 'match_syntax': 1, 'kind': ['delete', 'replace', 'textobj'], 'action': ['delete'], 'input': ['{']},
\ {'buns': ['\[\s*', '\s*\]'], 'nesting': 1, 'regex': 1, 'match_syntax': 1, 'kind': ['delete', 'replace', 'textobj'], 'action': ['delete'], 'input': ['[']},
\ {'buns': ['(\s*', '\s*)'], 'nesting': 1, 'regex': 1, 'match_syntax': 1, 'kind': ['delete', 'replace', 'textobj'], 'action': ['delete'], 'input': ['(']},
\ ]
" }}}
" Plugin vim-which-key {{{
set timeoutlen=500 " By default timeoutlen is 1000 ms
"nnoremap <silent> <leader> :WhichKey ','<CR>
call which_key#register(',', "g:which_key_map")
nnoremap <silent> <leader> :<c-u>WhichKey ','<CR>
vnoremap <silent> <leader> :<c-u>WhichKeyVisual ','<CR>
" Define prefix dictionary
let g:which_key_map = {}
" Second level dictionaries:
" 'name' is a special field. It will define the name of the group, e.g., leader-f is the "+file" group.
" Unnamed groups will show a default empty string.
" =======================================================
" Create menus based on existing mappings
" =======================================================
" You can pass a descriptive text to an existing mapping.
let g:which_key_map.m = { 'name' : 'match' }
let g:which_key_map.m.t = 'Match-CR'
let g:which_key_map.p = { 'p' : 'Reselect the text that was just pasted' }
let g:which_key_map.s = { 'name' : '+source' }
let g:which_key_map.s.v = 'Source-vimrc'
let g:which_key_map.t = { 'name' : '+tab' }
let g:which_key_map.t.v = 'Tab-vimrc'
" =======================================================
" Create menus not based on existing mappings:
" =======================================================
" Provide commands(ex-command, <Plug>/<C-W>/<C-d> mapping, etc.) and descriptions for existing mappings
let g:which_key_map.b = {
\ 'name' : '+buffer' ,
\ '1' : ['b1' , 'buffer 1'] ,
\ '2' : ['b2' , 'buffer 2'] ,
\ 'd' : ['bd' , 'delete-buffer'] ,
\ 'f' : ['bfirst' , 'first-buffer'] ,
\ 'h' : ['Startify' , 'home-buffer'] ,
\ 'l' : ['blast' , 'last-buffer'] ,
\ 'n' : ['bnext' , 'next-buffer'] ,
\ 'p' : ['bprevious' , 'previous-buffer'] ,
\ '?' : ['Buffers' , 'fzf-buffer'] ,
\ }
let g:which_key_map.f = {
\ 'name' : '+file' ,
\ 'n' : ['fn' , 'File Name to Clipboard'] ,
\ 'p' : ['fp' , 'Path Name to Clipboard'] ,
\ }
let g:which_key_map.F = {
\ 'name' : '+Function-Key' ,
\ 'F1' : ['help' , 'help'] ,
\ 'F2' : ['set nowrap' , 'set nowrap'] ,
\ 'F3' : ['Vex' , 'Vex'] ,
\ 'F4' : ['bfirst' , 'first-buffer'] ,
\ 'F5' : ['Startify' , 'home-buffer'] ,
\ 'F6' : ['call ToggleCursor()' , 'ToggleCursorLine'] ,
\ 'F7' : ['hi' , 'highlight'] ,
\ 'F8' : ['tabs' , 'Show all buffers in tabs'] ,
\ 'F9' : ['HTML Escape' , 'Escape Character Entity)'] ,
\ 'F10' : ['gJ' , 'join lines without producing a space'] ,
\ 'C-F1' : ['set go-=m' , 'Show Menu'] ,
\ 'C-F2' : ['set go-=T' , 'Show Toolbar'] ,
\ 'C-F3' : ['set go-=r' , 'Show Scroolba'] ,
\ 'C-F4' : ['laststatus=2' , 'Show Statusline'] ,
\ 'C-Ins' : ['tabnew' , 'tabnew'] ,
\ 'C-Del' : ['tabclose' , 'tabclose'] ,
\ }
" }}}
" AfterPlugin {{{
" 取消用Ctrl-F调用查找窗口
"unmap <C-F>
" Prevent single letter deletes to spam clipboard manager
nnoremap x "_x
"show a colored column (so I can see when I write a too-long line of code)
"set colorcolumn=70
"highlight ColorColumn ctermbg=darkred guibg=darkred
" }}}