-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
518 lines (453 loc) · 13.8 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
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Bundle 'gmarik/Vundle.vim'
" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
Bundle 'Valloric/YouCompleteMe'
Bundle 'rdnetto/YCM-Generator'
"Bundle 'Syntastic'
"Bundle 'rking/ag.vim'
Bundle 'dyng/ctrlsf.vim'
Bundle 'Raimondi/delimitMate'
Bundle 'kien/ctrlp.vim'
Bundle 'tacahiroy/ctrlp-funky'
Bundle 'Lokaltog/vim-easymotion'
Plugin 'godlygeek/tabular'
Plugin 'plasticboy/vim-markdown'
Bundle 'rosenfeld/conque-term'
Plugin 'zmj64351508/Tabmerge'
Bundle 'vim-scripts/Tagbar'
" Track the engine.
"Bundle 'SirVer/ultisnips'
" Snippets are separated from the engine. Add this if you want them:
"Bundle 'honza/vim-snippets'
" 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
" -------------Common vimrc start------------
"echo $VIMRUNTIME
"source $VIMRUNTIME/mswin.vim
source ~/.vim/magee.vim
" common
syntax on
filetype on
set nocompatible
" automatically read file when changed
set autoread
" indent
set autoindent
"filetype plugin off
"set smartindent
" tab expand and width
set tabstop=8
"set softtabstop=8
"set shiftwidth=8
set noexpandtab
" display setting
set showmatch
set hlsearch
set cursorline
" do not set lines and columns in console
if has("gui_running")
set lines=35 columns=118
set guioptions-=T
endif
set number
set nobackup
set display=lastline "display last line when it can't be display completely
set nolinebreak "can break a word at the end of the line
set wrap
set foldmethod=syntax
set foldcolumn=1
set foldlevel=999
set mouse=a
set nomousehide
set winaltkeys=no
set autochdir "auto change directory to the file dir
set incsearch "dispaly search result when searching
"set laststatus=2 "display status bar
"set statusline=%m%r%F\ \|\ %Y,%{&fileencoding}\ \|%=\ %l/%L,%c
" 设置在状态行显示的信息如下:
" %f 当前的文件名
" %F 当前全路径文件名
" %m 当前文件修改状态
" %r 当前文件是否只读
" %Y 当前文件类型
" %{&fileformat}
" 当前文件编码
" %{&fileencoding}
" 中文编码
" %b 当前光标处字符的 ASCII 码值
" %B 当前光标处字符的十六进制值
" %l 当前光标行号
" %c 当前光标列号
" %V 当前光标虚拟列号 (根据字符所占字节数计算)
" %p 当前行占总行数的百分比
" %% 百分号
" %L 当前文件总行数
" gui font
set guifont=monospace\ 11
set ttymouse=xterm
if &term =~ "xterm"
" 256 colors
let &t_Co = 256
" restore screen after quitting
let &t_ti = "\<Esc>7\<Esc>[r\<Esc>[?47h"
let &t_te = "\<Esc>[?47l\<Esc>8"
if has("terminfo")
let &t_Sf = "\<Esc>[3%p1%dm"
let &t_Sb = "\<Esc>[4%p1%dm"
else
let &t_Sf = "\<Esc>[3%dm"
let &t_Sb = "\<Esc>[4%dm"
endif
endif
colorscheme term_wombat
" show tab
set showtabline=3
function ShortTabLabel ()
let bufnrlist = tabpagebuflist(v:lnum)
let label = ''
" Add '+' if one of the buffers in the tab page is modified
for bufnr in bufnrlist
if getbufvar(bufnr, "&modified")
let label = '+'
break
endif
endfor
let label .= bufname (bufnrlist[tabpagewinnr (v:lnum) -1])
let filename = fnamemodify (label, ':t')
return filename
endfunction
set guitablabel=%{ShortTabLabel()}
function MyTabLine()
let s = ''
for i in range(tabpagenr('$'))
" select the highlighting
if i + 1 == tabpagenr()
let s .= '%#TabLineSel#'
else
let s .= '%#TabLine#'
endif
" set the tab page number (for mouse clicks)
let s .= '%' . (i + 1) . 'T'
" the label is made by MyTabLabel()
let s .= ' %{MyTabLabel(' . (i + 1) . ')} '
endfor
" after the last tab fill with TabLineFill and reset tab page nr
let s .= '%#TabLineFill#%T'
" right-align the label to close the current tab page
if tabpagenr('$') > 1
let s .= '%=%#TabLine#%999Xclose'
endif
return s
endfunction
function MyTabLabel(n)
let label = ''
let buflist = tabpagebuflist(a:n)
let winnr = tabpagewinnr(a:n)
if getbufvar(winnr, "&modified")
let label = '+'
endif
let label .= bufname(buflist[winnr - 1])
let filename = fnamemodify (label, ':t')
return filename
endfunction
set tabline=%!MyTabLine()
" c source file setting
set cino=:0
function OpenDefinationInTab(word)
tabnew
try
exec 'cs find g ' . a:word
catch /^Vim\%((\a\+)\)\=:E259/
tabc
endtry
endfunction
command Buffer2tab tabnew % | tabpre | q! | tabnext
" diff specific setting
function SplitCenter()
set noequalalways
set equalalways
endfunction
" auto wrap 2 split window
autocmd FilterWritePre * if &diff | setlocal wrap< | endif
" auto center split window
autocmd VimResized * if &diff | call SplitCenter() | endif
if &diff
"next and previous diff
noremap <F1> [czz
noremap <F2> ]czz
set foldcolumn=1
else
noremap <F1> <C-]>
noremap <F2> :call OpenDefinationInTab(expand("<cword>"))<cr>
" noremap <F2> :YcmCompleter GoTo<CR>zz
endif
autocmd FileType c call HighlightCfunction()
autocmd FileType c++ call HighlightCfunction()
autocmd FileType java call HighlightCfunction()
function! HighlightCfunction()
" c function highlight
syn match cFunction "\<[a-zA-Z_][a-zA-Z_0-9]*\>[^()]*)("me=e-2
syn match cFunction "\<[a-zA-Z_][a-zA-Z_0-9]*\>\s*("me=e-1
hi def link cFunction Function
endfunc
autocmd FileType python setlocal noexpandtab sta sw=8 sts=8
" some key map
nmap j gj
nmap k gk
noremap <C-d> <C-d>zz
noremap <C-u> <C-u>zz
" tab movement
noremap <C-left> :tabp<CR>
noremap <C-right> :tabn<CR>
noremap <C-S-left> :tabm -1<CR>
noremap <C-S-right> :tabm +1<CR>
noremap <C-h> :tabp<CR>
noremap <C-l> :tabn<CR>
noremap <C-j> :tabm -1<CR>
noremap <C-k> :tabm +1<CR>
noremap <C-up> :tabnew<CR>
noremap <C-e> :tabnew<CR>
noremap <A-1> 1gt
noremap <A-2> 2gt
noremap <A-3> 3gt
noremap <A-4> 4gt
noremap <A-5> 5gt
noremap <A-6> 6gt
noremap <A-7> 7gt
noremap <A-8> 8gt
noremap <A-9> 9gt
" split buffer switch
map <a-w> <c-w>
map <a-l> <c-w>l
map <a-k> <c-w>k
map <a-j> <c-w>j
map <a-h> <c-w>h
imap <a-l> <esc><c-w>li
imap <a-k> <esc><c-w>ki
imap <a-j> <esc><c-w>ji
imap <a-h> <esc><c-w>hi
nmap <A-.> :<up><CR>
noremap <F3> <C-o>
noremap <F4> <C-i>
noremap <F5> g*N
nnoremap <F6> :YcmForceCompileAndDiagnostics<CR>
" symbal
nmap <Leader>s :cs find s <C-R>=expand("<cword>")<CR><CR>
" definition
nmap <Leader>g :cs find g <C-R>=expand("<cword>")<CR><CR>
" calling references
nmap <Leader>c :cs find c <C-R>=expand("<cword>")<CR><CR>
"nmap <Leader>t :cs find t <C-R>=expand("<cword>")<CR><CR>
"nmap <Leader>e :cs find e <C-R>=expand("<cword>")<CR><CR>
"nmap <Leader>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
"nmap <Leader>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
"nmap <Leader>d :cs find d <C-R>=expand("<cword>")<CR><CR>
nnoremap <Leader>f :CtrlPFunky<Cr>
" narrow the list down with a word under cursor
"nnoremap <Leader>fU :execute 'CtrlPFunky ' . expand('<cword>')<Cr>
""""""""""ctags""""""""""""
set tags=tags;/
""""""""""cscope""""""""""""
"if has("cscope")
" set csto=0
" set cst
" set csverb
" set cspc=3
" "add any database in current dir
" if filereadable("GTAGS")
" cs add GTAGS
" "else search cscope.out elsewhere
" else
" let cscope_file=findfile("GTAGS", ".;")
" let cscope_pre=matchstr(cscope_file, ".*/")
" if !empty(cscope_file) && filereadable(cscope_file)
" exe "cs add" cscope_file cscope_pre
" endif
" endif
"endif
"using GNU GLOBAL
set cscopeprg=gtags-cscope
"let g:GtagsCscope_Auto_Load = 1
"let g:GtagsCscope_Auto_Map = 1
"let g:GtagsCscope_Absolute_Path = 1
set csto=0
set csverb
set cst
"set cscopequickfix=c-,d-,e-,g-,i-,s-,t-
function! FindFiles(pat, ...)
let path = ''
for str in a:000
let path .= str . ','
endfor
if path == ''
let path = &path
endif
echo 'finding...'
redraw
call append(line('$'), split(globpath(path, a:pat), '\n'))
echo 'finding...done!'
redraw
endfunc
function! VimEnterCallback()
for f in argv()
"if fnamemodify(f, ':e') != 'c' && fnamemodify(f, ':e') != 'h' && fnamemodify(f, ':e') != 'java'
"continue
"endif
call LoadGtags(f)
endfor
endfunc
function! FindGtags(f)
let gtags = ""
let dir = fnamemodify(a:f, ':p:h')
while 1
let tmp = dir . '/GTAGS'
if filereadable(tmp)
let gtags = tmp
break
elseif dir == '/'
break
endif
let dir = fnamemodify(dir, ":h")
endwhile
return gtags
endfunc
function! LoadGtags(f)
let gtags = FindGtags(a:f)
set nocsverb
exec 'cs add ' . gtags . ' ' . '.' . ' -a'
set csverb
endfunc
function! UpdateGtags(f)
let dir = fnamemodify(a:f, ':p:h')
let fname = fnamemodify(a:f, ':p')
let found = 0
while 1
let tmp = dir . '/GTAGS'
if filereadable(tmp)
let found = 1
break
elseif dir == '/'
break
endif
let dir = fnamemodify(dir, ":h")
endwhile
if found == 1
exe 'silent !cd ' . dir . ' && gtags --single-update ' . fname . '&'
endif
endfunction
au VimEnter * call VimEnterCallback()
au BufEnter * call LoadGtags(expand('<afile>'))
au BufWritePost * call UpdateGtags(expand('<afile>'))
""""""""""youcompleteme""""""""""""
let g:ycm_show_diagnostics_ui = 0
let g:ycm_enable_diagnostic_signs = 0
let g:ycm_enable_diagnostic_highlighting = 0
let g:ycm_complete_in_comments = 0
let g:ycm_collect_identifiers_from_comments_and_strings = 0
"let g:ycm_collect_identifiers_from_tags_files = 1 may crash if tags file very
"huge
let g:ycm_seed_identifiers_with_syntax = 1
set completeopt-=preview "do not dispaly preview
"let g:ycm_add_preview_to_completeopt = 1
"let g:ycm_autoclose_preview_window_after_completion = 1
"let g:ycm_autoclose_preview_window_after_insertion = 1
""""""""""syntastic""""""""""""
"set error or warning signs
"let g:syntastic_enable_signs = 0
"let g:syntastic_error_symbol = 'x'
"let g:syntastic_warning_symbol = '⚠'
"whether to show balloons
"let g:syntastic_enable_balloons = 1
""""""""""Ag""""""""""""
let g:aghighlight=1
let g:agprg="ag --column --smart-case"
""""""""""ultisnips""""""""""""
" make YCM compatible with UltiSnips (using supertab)
"let g:ycm_key_list_select_completion = ['<C-j>', '<Down>']
"let g:ycm_key_list_previous_completion = ['<C-k>', '<Up>']
"let g:SuperTabDefaultCompletionType = '<C-j>'
"
"" better key bindings for UltiSnipsExpandTrigger
"let g:UltiSnipsExpandTrigger = "<tab>"
"let g:UltiSnipsJumpForwardTrigger = "<tab>"
"let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"
""""""""""delimitMate""""""""""""
let delimitMate_expand_cr = 1
""""""""""ctrlp""""""""""""
" open in new tabpage
"let g:ctrlp_prompt_mappings = {
"\ 'AcceptSelection("e")': ['<c-r>'],
"\ 'AcceptSelection("t")': ['<cr>', '<c-m>'],
"\ }
let g:ctrlp_follow_symlinks = 1
let g:ctrlp_clear_cache_on_exit = 0
let g:ctrlp_max_depth = 40
let g:ctrlp_max_files = 0
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/]\.(git|hg|svn)$',
\ 'file': '\v\.(o|exe|so|dll)$',
\ }
let g:ctrlp_extensions = ['funky']
let g:ctrlp_funky_syntax_highlight = 1
""""""""""ctrlp""""""""""""
map ,, <Plug>(easymotion-prefix)
nmap f <Plug>(easymotion-f)
nmap F <Plug>(easymotion-F)
nmap t <Plug>(easymotion-t)
nmap T <Plug>(easymotion-T)
nmap w <Plug>(easymotion-iskeyword-w)
nmap W <Plug>(easymotion-W)
nmap b <Plug>(easymotion-iskeyword-b)
nmap B <Plug>(easymotion-B)
nmap e <Plug>(easymotion-iskeyword-e)
nmap E <Plug>(easymotion-E)
nmap ge <Plug>(easymotion-iskeyword-ge)
nmap gE <Plug>(easymotion-gE)
"nmap j <Plug>(easymotion-j)
"nmap k <Plug>(easymotion-k)
"nmap n <Plug>(easymotion-n)
"nmap N <Plug>(easymotion-N)
nmap s <Plug>(easymotion-s)
"""""""""""""ctrlsf"""""""""""""""""
let g:ctrlsf_auto_close = 0
let g:ctrlsf_regex_pattern = 1
let g:ctrlsf_default_root = 'project'
nmap <C-F> <Esc>
nmap <C-F>f <Plug>CtrlSFPrompt
vmap <C-F>F <Plug>CtrlSFVwordPath
vmap <C-F>f <Plug>CtrlSFVwordExec
nmap <C-F>n <Plug>CtrlSFCwordPath
nmap <C-F>p <Plug>CtrlSFPwordPath
nnoremap <C-F>o :CtrlSFOpen<CR>
nnoremap <C-F>t :CtrlSFToggle<CR>
inoremap <C-F>t <Esc>:CtrlSFToggle<CR>
function UpdateAddress(start, end, step)
for curline in range(a:start, a:end)
let content = getline(curline)
let content = printf("%s\t// 0x%x", content, (curline - a:start)*a:step)
call setline(curline, content)
endfor
endfunction
"""""""""""""tabmerge"""""""""""""""""
let g:tabmerge_location = 'left'