-
Notifications
You must be signed in to change notification settings - Fork 0
/
_vimrc
690 lines (562 loc) · 17.2 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
" vim: foldmethod=marker foldmarker={,}{
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Maintainer: Mike Guo <[email protected]>
" Version: 5.0
" Last Change: 2012/07/13 10:43:58
"
" Fixed (win32 compatible) by: Mike Guo
" This vimrc file is tested on platforms on win32 and vim7.3
"
" Tip:
" If you find anything that you can't understand than do this:
" help keyword OR helpgrep keyword
" How to show the value of runtimepath: echo &rtp
"
" Example:
" Go into command-line mode and type helpgrep nocompatible, ie.
" :helpgrep nocompatible
" then press <leader>qo to see the results, or :botright cw
" Section:
" -> General
" -> Mappings
" -> Autocmd
" -> Customcmd
" -> Plugin
"}
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General{
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set nocompatible "get out of VI's compatible mode
" Use pathogen to easily modify the runtime path to include all plugins under the ~/.vim/bundle directory
silent! call pathogen#infect()
" encoding
if has("multi_byte")
set encoding=utf-8
if &termencoding == ""
set termencoding=utf-8
endif
setglobal fileencoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
endif
" language
set langmenu=zh_CN.utf-8
language messages zh_CN.utf-8
" Sets how many lines of history VIM has to remember, default 50
set history=400
filetype plugin indent on " Enable filetype plugin
syntax on " enable syntax
" Set to auto read when a file is changed from the outside
set autoread
" Set mapleader
let g:mapleader = ","
let g:maplocalleader = "_"
noremap \ ,
" Always display line numbers and ruler
set number
set ruler
"The commandbar is 2 high
set cmdheight=2
" allow buffer switching without saving
set hidden
" Allow backspacing over indent, eol, and the start of an insert
set backspace=eol,start,indent
" backspace and cursor keys wrap to
set whichwrap+=<,>,h,l
" Ignore case when searching by default
set ignorecase
set smartcase
" Highlight search and display incremental matches
set hlsearch
set incsearch
"Don't redraw while executing macros
set lazyredraw
"show matching bracets
set showmatch
" show whitespace and tab characters
set listchars=tab:>.,trail:.,extends:#,nbsp:.
set list
set nosol "nostartofline
" Always show the status line
set laststatus=2
if has('title') && (has('gui_running') || &title)
set titlestring=
set titlestring+=%t\ " file name
set titlestring+=%h%m%r%w " flag
set titlestring+=\ -\ %{substitute(getcwd(),\ $HOME,\ '~',\ '')} " working directory
endif
set fo-=t "remove auto format text
set textwidth=120
set colorcolumn=+1
set linebreak "Wrap lines at convenient points
set nowrap
" Tabs
set smarttab
set expandtab
set tabstop=4
set shiftwidth=4
set softtabstop=4
" Indent
set autoindent
set smartindent
" c-indent options
"set cinkeys-=0#
set cinoptions=:0,l1,g0,t0,(s,u0,(0,W4,j1,N-s
" Completion
set wildmenu
" command <Tab> completion, list matches, then longest common part, then all.
set wildmode=list:longest,full
set wildignore+=*.o,*.obj,*.pyc,*.swp,*.zip,*.exe,*.so
set completeopt=longest,menu,preview
" ignore the annoying scan for header files
set complete-=i
" Fonts
if has("mac") || has("macunix")
set gfn=Monaco:h12
set shell=/bin/bash
elseif has("win32")
set gfn=DejaVu_Sans_Mono:h11,Consolas:h10
set gfw=Yahei_Mono:h11
elseif has ("unix")
set gfn=Monospace\ 10
set shell=/bin/bash
endif
" scroll
set scrolloff=2
" Fold
set foldcolumn=1
if has("gui_running")
set guioptions-=a
" set guioptions+=b " the horizontal scrollbar
set guioptions-=r "Hide the right scrollbar
set guioptions-=T
set guioptions-=e
set guioptions-=m "Hide menu bar
" The following command must be placed before the colo command
set background=dark
try
let g:solarized_contrast="high"
let g:solarized_italic=0
colo solarized
catch
colo desert
endtry
if has('mac')
set transparency=15
endif
" Disable acces to menu using alt key
set winaltkeys=no
else
set t_Co=256
let g:solarized_termtrans=1
colo solarized
endif
set grepprg=rg\ --vimgrep
" Highlight current line, default is off comment it
" set nocursorline
" standard file type
if has("win32")
set ffs=dos,unix,mac
else
set ffs=unix,dos,mac
endif
" File, backup and undo
set nobackup
set nowritebackup
set noswapfile
if !exists("$temp") && has("unix")
let $temp="/tmp"
endif
set directory=$temp
set backupdir=$temp
set undodir=~/vimfiles/undodir,$temp
set undofile
" Session
set sessionoptions-=options
set sessionoptions-=localoptions
set sessionoptions-=blank
set t_vb=
" Not clear the screen after exit
set t_ti=
set t_te=
set tm=500 "timeoutlen
if exists("&ambiwidth")
set ambiwidth=double
endif
"}
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" mswin{
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if has("win32")
source $VIMRUNTIME/mswin.vim
"clear the keymodel in order to let Ctrl-F, Ctrl-B select the text in visual mode
set km=
" CTRL-C shortcut on normal mode
nnoremap <C-C> "+y
" we want to use the C-Y/C-E in insert mode
iunmap <C-Y>
unmap <C-Y>
nunmap <C-a>
if v:version >= 800
silent! unmap <C-F>
endif
endif
"}
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" mappings {
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Quickfix window
" Do :help cope if you are unsure what cope is. It's super useful!
" quickfix ref shorcut :cNext :cprevious
nnoremap <leader>qo :botright copen<CR>
nnoremap <leader>qc :call setqflist([])<CR>
nmap <F4> :cnext<CR>
nmap <S-F4> :cprevious<CR>
" Command mode
" Smart mappings on the command line
cno $h e ~/
if !has("unix")
cno $d e ~/Desktop/
endif
cno $j e ./
cno $c e <C-R>=expand("%:p:h")<CR>
cno $n expand('%:p')
cno $p <C-R>=getcwd()<CR>
" $q is super useful when browsing on the command line
cno $q <C-\>eDeleteTillSlash()<cr>
" Bash like keys for the command line
cnoremap <C-A> <Home>
cnoremap <C-B> <Left>
cnoremap <C-F> <Right>
cnoremap <C-D> <Delete>
cnoremap <M-b> <S-Left>
cnoremap <M-f> <S-Right>
cnoremap <M-d> <S-right><Delete>
cnoremap <C-g> <C-c>
cnoremap <C-P> <Up>
cnoremap <C-N> <Down>
cnoremap <C-K> <C-U>
func! DeleteTillSlash()
let g:cmd = getcmdline()
if (has("win16") || has("win32")) && !&shellslash
let g:cmd_edited = substitute(g:cmd, "\\(.*\[\\\\]\\).*", "\\1", "")
else
let g:cmd_edited = substitute(g:cmd, "\\(.*\[/\]\\).*", "\\1", "")
endif
if g:cmd == g:cmd_edited
if (has("win16") || has("win32")) && !&shellslash
let g:cmd_edited = substitute(g:cmd, "\\(.*\[\\\\\]\\).*\[\\\\\]", "\\1", "")
else
let g:cmd_edited = substitute(g:cmd, "\\(.*\[/\]\\).*/", "\\1", "")
endif
endif
return g:cmd_edited
endfunc
" Navigation
nnoremap j gj
nnoremap k gk
" This is totally awesome - remap jj to escape in insert mode. You'll never type jj anyway, so it's great!
inoremap jj <Esc>
nnoremap JJ <Nop>
"Remap VIM 0
nnoremap 0 ^
vnoremap 0 ^
noremap <Home> g0
noremap <End> g$
"Reselect visual block after indent/outdent
vnoremap < <gv
vnoremap > >gv
" Smart way to move btw. windows
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
" Tags
set tags=tags;/
nnoremap <leader>tn :ptnext<CR>
nnoremap <leader>tp :ptNext<CR>
" Use the arrows to something usefull
map <c-right> :bn<cr>
map <c-left> :bp<cr>
" Tab configuration
map <leader>te :tabedit
map <leader>tc :tabclose<cr>
map <leader>tm :tabmove
" When pressing <leader>cd switch to the directory of the open buffer
map <leader>cd :cd %:p:h<cr>
" Close all the buffers
map <leader>ba :%bd!<cr>
nnoremap <leader>y "*y
vnoremap <leader>y "*y
nnoremap <leader>d "*d
vnoremap <leader>d "*d
vnoremap <leader>p "*p
"Move a line of text using ALT+[jk] or Comamnd+[jk] on mac
nmap <M-j> mz:m+<cr>`z
nmap <M-k> mz:m-2<cr>`z
vmap <M-j> :m'>+<cr>`<my`>mzgv`yo`z
vmap <M-k> :m'<-2<cr>`>my`<mzgv`yo`z
" Bubble single lines, they depends unimpair plugin
nmap <C-Up> [e
nmap <C-Down> ]e
" Bubble multiple lines
vmap <C-Up> [egv
vmap <C-Down> ]egv
" Visually select the text that was last edited/pasted
nmap gV `[v`]
nmap <leader>fd :se ff=dos<cr>
nmap <leader>fu :se ff=unix<cr>
" Fast editing of the .vimrc
map <leader>ev :e! $MYVIMRC<cr>
" clear search highlight
map <silent> <leader><cr> :noh<cr>
" Spell checks
"Pressing ,ss will toggle and untoggle spell checking
map <leader>ss :setlocal spell!<cr>
"Remove the Windows ^M
noremap <Leader>rm mmHmt:%s/<C-Q><cr>//ge<cr>'tzt'm
"Remove duplicated empty lines: http://vim.wikia.com/wiki/Power_of_g
map QE :%s/^\s*$\n^\s*$//g<CR>
map QU :g/^\(.*\)\ze\n\%(.*\n\)*\1$/d<CR>
function! HighlightRepeats() range
let lineCounts = {}
let lineNum = a:firstline
while lineNum <= a:lastline
let lineText = getline(lineNum)
if lineText != ""
let lineCounts[lineText] = (has_key(lineCounts, lineText) ? lineCounts[lineText] : 0) + 1
endif
let lineNum = lineNum + 1
endwhile
exe 'syn clear Repeat'
for lineText in keys(lineCounts)
if lineCounts[lineText] >= 2
exe 'syn match Repeat "^' . escape(lineText, '".\^$*[]') . '$"'
endif
endfor
endfunction
command! -range=% HighlightRepeats <line1>,<line2>call HighlightRepeats()
"Remove indenting on empty line
map <Leader>ri :%s/\s*$//g<cr>:noh<cr>''
map <leader>bb :cd ..<cr>
map <leader>pp :setlocal paste!<cr>
" Diff shortcuts
noremap <S-F1> :browse vert diffsplit<CR>
" Copy current buffer path relative to root of VIM session to system clipboard
nnoremap <Leader>yy :let @*=expand("%:p")<cr>:echo "Copied file path to clipboard"<cr>
" Copy current filename to system clipboard
nnoremap <Leader>yf :let @*=expand("%:t")<cr>:echo "Copied file name to clipboard"<cr>
" Copy current buffer path without filename to system clipboard
nnoremap <Leader>yd :let @*=expand("%:p:h")<cr>:echo "Copied file directory to clipboard"<cr>
cnoremap <expr> %% getcmdtype() == ':' ? expand('%:h').'/' : '%%'
map <leader>ew :e %%
map <leader>es :sp %%
cnoreabbrev json %!python -m json.tool
" copied from http://stackoverflow.com/questions/15108622/how-to-yank-a-code-block-without-folded-content
":g/^/if line('.')==foldclosed('.') || foldclosed('.')==-1|y Z|endif<CR>
nnoremap <leader>cf :g/^/if line('.')==foldclosed('.') <Bar><Bar> foldclosed('.')==-1<Bar>y Z<Bar>endif<CR>
"}
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" autocmd{
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
augroup vimrc_commands
autocmd!
" Copied from http://vim.wikia.com/wiki/Keep_folds_closed_while_inserting_text
" Don't screw up folds when inserting text that might affect them, until
" leaving insert mode. Foldmethod is local to the window. Protect against
" screwing up folding when switching between windows.
" autocmd InsertEnter * if !exists('w:last_fdm') | let w:last_fdm=&foldmethod | setlocal foldmethod=manual | endif
" autocmd InsertLeave * if exists('w:last_fdm') | let &l:foldmethod=w:last_fdm | unlet w:last_fdm | endif
autocmd InsertEnter * set noignorecase
autocmd InsertLeave * set ignorecase
" When vimrc is edited, reload it
"autocmd! BufWritePost $MYVIMRC source $MYVIMRC
autocmd BufReadPost,FileReadPost,BufNewFile * normal zR
"Comment for C like language abbrevations for comments
autocmd BufNewFile,BufRead *.js,*.htc,*.c,*.tmpl,*.css ino $c /**<cr> **/<esc>O
augroup END
"}
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Customcmd{
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Redirect to clipboard.
" copied from http://derekwyatt.org/
function! RedirToClipboardFunction(cmd,...)
let cmd = a:cmd . " " . join(a:000, " ")
redir @z>
exe cmd
redir END
let @*=@z
endfunction
command! -complete=command -nargs=+ RedirToClipboard
\ silent! call RedirToClipboardFunction(<f-args>)
cab rc RedirToClipboard
function! s:DiffWithSaved()
let filetype=&ft
diffthis
vnew | r # | normal! 1Gdd
diffthis
exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype
endfunction
com! DiffSaved call s:DiffWithSaved()
"}
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Language{
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" c/cpp
let g:c_gnu=1
" Java.vim
let g:java_comment_strings=1
let g:java_highlight_all=1
let g:java_highlight_debug=1
let g:java_highlight_functions="style"
let g:java_space_errors=1
let g:java_mark_braces_in_parens_as_errors=1
" Xml.vim
" Turn on the following line will break Csharp's syntax
" let g:xml_syntax_folding=1
let g:xml_syntax_folding=1
au FileType xml setlocal foldmethod=syntax
let g:sql_type_default = "sqlserver"
"}
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugin{
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" load the matchit plugin.
runtime macros/matchit.vim
"BufExplorer
let g:bufExplorerDefaultHelp=0
let g:bufExplorerShowRelativePath=1
let g:bufExplorerSortBy = "name"
let g:bufExplorerShowNoName=1
"NERDTree
"let g:NERDTreeWinPos = "right"
let g:NERDTreeShowBookmarks=1
let g:NERDTreeShowLineNumbers=1
let g:NERDTreeMouseMode=3
" let g:NERDTreeQuitOnOpen=1
nmap <leader>nn :NERDTreeToggle<CR>
nmap <leader>nf :NERDTreeFind<CR>
"MRU
let MRU_Max_Entries = 400
map <leader>fr :MRU<CR>
"noremap <C-F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
noremap <C-F12> :call GenCTagsAll()<CR>
"let g:tagbar_left = 1
map <leader>t :TagbarToggle<cr>
" tagbar settings for language
let g:tagbar_type_ps1 = { 'ctagstype' : 'powershell', 'kinds' : [ 'd:definition', ], 'sort' : 0 }
" gen ctags for all languages
function! GenCTagsAll()
"Command is:
let cwd = getcwd()
let tagfile = cwd . "\\tags"
" let cmd = "!ctags -f \"" . tagfile . "\" -R --c++-kinds=+p --fields=+iaS --extra=+q "
" " The following line will generate tags only for the languages in the list
" let cmd = cmd . "--languages=c,c++,c\\#,python,vim,html,lua,javascript,java "
" let cmd = cmd . "--langmap=c++:+.inl,c:+.fx.fxh.hlsl.vsh.psh.cg.shd,javascript:+.as "
" let cmd = cmd . "."
" silent! execute cmd
" let cmd = "!ctags -f \"" . tagfile ."\" -R --c++-kinds=+p --fields=+iaS --extra=+q --language-force=c++ \"" . cwd . "\""
let cmd = "!ctags -R ."
execute cmd
endfunction
" cscope
if has('cscope')
set csprg=cscope.exe
set cscopetag cscopeverbose
if has('quickfix')
set cscopequickfix=s-,c-,d-,i-,t-,e-
endif
cnoreabbrev csa cs add
cnoreabbrev csf cs find
cnoreabbrev csk cs kill
cnoreabbrev csr cs reset
cnoreabbrev css cs show
cnoreabbrev csh cs help
command! -nargs=0 Cscope cs add $VIMSRC/src/cscope.out $VIMSRC/src
endif
function! GenCscopeTag()
if(executable('cscope') && has("cscope") )
silent! execute "!dir /s /b *.c,*.cpp,*.h,*.hpp,*.inl > cscope.files"
silent! execute "!cscope -b"
if filereadable("cscope.out")
silent! execute "cs add cscope.out"
endif
endif
endf
noremap <S-F12> :call GenCscopeTag()<CR>
function! LoadCscope()
let db = findfile("cscope.out", ".;")
if (!empty(db))
let path = strpart(db, 0, match(db, "/cscope.out$"))
set nocsverb " suppress 'duplicate connection' error
exe "cs add " . db . " " . path
set csverb
endif
endfunction
au BufEnter /* call LoadCscope()
""SuperTab
"" The following two lines are to reverse the TAB selection order
"let g:SuperTabDefaultCompletionType = "context"
"" The following setting will cause vim deadlock
""let g:SuperTabLongestHighlight=1
"
"let g:SuperTabLongestEnhanced=1
" CtrlP
" nnoremap <leader>ff :CtrlP<CR>
nnoremap <leader>ff :FZF<CR>
nnoremap <leader>fb :Buffers<CR>
let g:ctrlp_working_path_mode = 0
let g:ctrlp_match_window_reversed = 0
if has("win32")
let g:ctrlp_user_command = 'dir %s /-n /b /s /a-d'
else
let g:ctrlp_user_command = 'find %s -type f'
endif
"Alternate
" map <F12> :A<CR>
let g:alternateExtensions_h = "c,cpp,cxx,cc,CC,m,mm"
let g:alternateExtensions_H="cpp,mm,c,m"
let g:alternateExtensions_hpp="cpp,mm,c,m"
let g:alternateExtensions_m="h"
let g:alternateExtensions_mm="h,hpp"
" Snipmate
let g:snips_author = 'Mike Guo'
" EasyMotion
let g:EasyMotion_leader_key="'"
" YankRing
if has("win32")
let g:yankring_clipboard_monitor = 0
endif
let g:yankring_window_auto_close = 0
let g:yankring_zap_keys = 'f t'
"Space
let g:space_no_character_movements = 1 " disable the movement in order to make snipMate work correctly
let g:space_no_search = 1
let g:space_no_jump = 1
" delimitMate
let g:delimitMate_expand_cr = 0
au FileType xml,html let b:delimitMate_matchpairs = "(:),[:],{:}"
" omnicpp_complete
"inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
let g:OmniCpp_SelectFirstItem=2 "Select the first item in pop-up
" Session
let g:session_autoload=0
let g:sessionman_save_on_exit=0
" SourceDepot
if has("win32")
map <silent> <leader>se :call SDCheckOut()<cr>
map <silent> <leader>sr :call SDRevertChanges()<cr>
map <silent> <Leader>so :call SDdiffopened()<cr>
endif
" airline
let g:airline#extensions#branch#enabled = 0
"neocomplete
if has("lua")
let g:neocomplete#enable_at_startup = 1
endif
"}
let g:pymode_python = 'python3'
if filereadable(expand("~/_vimrc.local"))
source ~/_vimrc.local
endif