-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path_vimrc
More file actions
633 lines (588 loc) · 17.4 KB
/
_vimrc
File metadata and controls
633 lines (588 loc) · 17.4 KB
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
" 是否启用插件
let g:EnablePlugin = 1
function IsWindows()
if(has("win32") || has("win64") || has("win95") || has("win16"))
return 1
else
return 0
endfunction
" 语言设置, 为了解决乱码问题
if IsWindows()
set helplang=cn
let $LANG='en'
set langmenu=en
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
endif
"====================插件配置开始====================
if g:EnablePlugin
set nocompatible " be iMproved, required
filetype off " required
try
" set the runtime path to include Vundle and initialize
if IsWindows()
set rtp+=$VIM/vimfiles/bundle/Vundle.vim/
call vundle#begin('$VIM/vimfiles/bundle')
else
set rtp+=~/.vim/bundle/Vundle.vim/
call vundle#begin('~/.vim/bundle')
endif
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
Plugin 'VundleVim/Vundle.vim'
" colorscheme
Plugin 'itruth/molokai'
" ctags use https://github.com/universal-ctags/ctags-win32/releases
" Do not use ctags58
Plugin 'itruth/auto-pairs'
Plugin 'majutsushi/tagbar'
Plugin 'scrooloose/nerdtree'
Plugin 'scrooloose/nerdcommenter'
Plugin 'vim-latex/vim-latex'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'gko/vim-coloresque'
Plugin 'ctrlpvim/ctrlp.vim'
Plugin 'tpope/vim-surround'
Plugin 'tpope/vim-repeat'
Plugin 'rust-lang/rust.vim'
" Markdown
Plugin 'tamlok/vim-markdown.git'
Plugin 'kannokanno/previm'
Plugin 'tyru/open-browser.vim'
" 部分插件需要python支持
if has('python3')
Plugin 'sirver/ultisnips'
Plugin 'itruth/vim-snippets'
Plugin 'ycm-core/YouCompleteMe'
endif
" 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
catch
echo "[Vundle Error]"
echo "Vundle is not installed"
echo "Vundle: https://github.com/VundleVim/Vundle.vim"
endtry
" 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
endif
"====================插件配置结束====================
" 语法高亮
syntax on
" 配色方案
try
colorscheme molokai
catch /^Vim\%((\a\+)\)\=:E185/ " catch error E185
if g:EnablePlugin
echo "[Colorscheme Error]"
echo "set colorscheme to molokai failed"
echo "colorscheme will set to torte if molokai is missing"
echo "Run :PluginInstall if vundle is already installed"
endif
colorscheme torte
endtry
" 启动不显示提示
set shortmess=atI
" 窗口位置
"winpos 100 100
" 窗口大小
set lines=30 columns=110
" 设置字体
if IsWindows()
set guifont=Courier_New:h10:cANSI
else
set guifont=Courier\ New\ 11
endif
" 显示行号
set nu
" 显示标尺
set ruler
" 不显示图形按钮
set go=
" 突出显示当前行
set cursorline
" 显示输入的命令
set showcmd
" 设置编码格式
set encoding=utf-8
set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
" 代码补全
set completeopt=preview,menu
" 去掉输入错误的提示声音
set noeb
" 在处理未保存或只读文件的时候,弹出确认
set confirm
"搜索逐字符高亮
set hlsearch
set incsearch
" 使退格键(backspace)正常处理indent, eol, start等
set backspace=2
" 允许backspace和光标键跨越行边界
set whichwrap+=<,>,h,l
" 设置手动折叠
set foldenable
set foldmethod=manual
" 去掉vi一致性模式
set nocompatible
" 字符间插入的像素行数目
set linespace=0
" 自动读取和保存
set autoread
set autowrite
" 自动缩进
set autoindent
set cindent
" Tab键的宽度
set tabstop=4
" 统一缩进为4
set softtabstop=4
set shiftwidth=4
" 不要用空格代替制表符
set noexpandtab
" 为C程序提供自动缩进
set smartindent
" 在行和段开始处使用制表符
set smarttab
" 不生成临时文件(这样做VIM将无法撤销上次文件的修改)
set nobackup
set noswapfile
" 设置匹配括号高亮时间
set showmatch
set matchtime=1
" 设置魔术
set magic
" 共享剪贴板
set clipboard+=unnamed
" 允许使用鼠标
set mouse=a
set selection=exclusive
set selectmode=mouse,key
"""""""""""Alt+n快捷切换Tab"""""""""""""""""""""""""""""""
function! TabPos_ActivateBuffer(num)
let s:count = a:num
exe "tabfirst"
exe "tabnext" s:count
endfunction
function! TabPos_Initialize()
for i in range(1, 9)
exe "map <M-" . i . "> :call TabPos_ActivateBuffer(" . i . ")<CR>"
endfor
exe "map <M-0> :call TabPos_ActivateBuffer(10)<CR>"
endfunction
autocmd VimEnter * call TabPos_Initialize()
""""""""""""""""""""""""""""""""""""""""""""""""""""
"新文件标题
""""""""""""""""""""""""""""""""""""""""""""""""""""
"新建.c,.cpp,.java,.bat文件,自动插入文件头
autocmd BufNewFile *.cpp,*.[ch],*.java,*.bat exec ":call SetTitle()"
""定义函数SetTitle,自动插入文件头
func SetTitle()
if &filetype == 'bat'
call append(0, "@echo off")
call append(1, "")
elseif &filetype == 'java'
call append(0, "import java.util.*;")
call append(1, "")
elseif expand('%:e') == 'cpp'
"set dictionary+=cpp_h.dic
call append(0, "#include <iostream>")
call append(1, "using namespace std;")
call append(2, "")
elseif expand('%:e') == 'h'
if filereadable(expand('%:r').'.c')
call append(0, "#ifndef ".toupper(expand("%:r"))."_H")
call append(1, "#define ".toupper(expand("%:r"))."_H")
call append(2, "")
call append(3, "#endif")
exec "normal 3G"
else
call append(0, "#ifndef ".toupper(expand("%:r"))."_H")
call append(1, "#define ".toupper(expand("%:r"))."_H")
call append(2, "")
call append(3, "class ".expand("%:r")."{")
call append(4, " public:")
call append(5, " ".expand("%:r")."();")
call append(6, " ")
call append(7, "};")
call append(8, "")
call append(9, "#endif")
exec "normal 7G$"
endif
elseif &filetype == 'c'
call append(0, "#include <stdio.h>")
call append(1, "")
endif
"新建文件后,自动定位到文件末尾
autocmd BufNewFile * normal G
endfunc
""""""""""""""""""""""""""""""""""""""""""""""""""""
"键盘命令
""""""""""""""""""""""""""""""""""""""""""""""""""""
" 禁插件情况下的自动补全
if !g:EnablePlugin
inoremap ( ()<ESC>i
inoremap ) <C-R>=ClosePair(')')<CR>
inoremap <M-(> (
inoremap <M-)> )
inoremap {<CR> {<CR>}<ESC>O
inoremap {<TAB> {}<ESC>i
inoremap } <C-R>=ClosePair('}')<CR>
inoremap <M-{> {
inoremap <M-}> }
inoremap [ []<ESC>i
inoremap ] <C-R>=ClosePair(']')<CR>
inoremap <M-[> [
inoremap <M-]> ]
inoremap " ""<ESC>i
inoremap ' ''<ESC>i
inoremap <M-"> "
inoremap <M-'> '
"删括号用
inoremap <S-BACKSPACE> <DEL><BACKSPACE>
function! ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endfunction
endif
" 映射全选 ctrl+a
nnoremap <C-A> ggvG$
"自动对齐
nnoremap <F12> gg=G
"窗口间切换
nnoremap <F2> <C-w>w
"去空行
nnoremap <C-F2> :g/^\s*$/d<CR>
"新建标签
nnoremap <M-F3> :tabnew<CR>
"列出当前目录文件
noremap <F3> :tabnew .<CR>
"Alt+o/O以命令模式插入行
noremap <M-o> o<Esc>
noremap <M-O> O<Esc>
"insert模式emacs快捷键
inoremap <C-L> <ESC>zza
inoremap <C-F> <ESC>la
inoremap <C-N> <ESC>ja
inoremap <C-P> <ESC>ka
inoremap <C-B> <ESC>i
inoremap <C-A> <ESC>I
inoremap <C-E> <ESC>A
inoremap <C-K> <ESC>C
inoremap <M-<> <ESC>ggi
inoremap <M->> <ESC>GA
"\ 命令定义
nnoremap \im :call SetNewLine()<CR>Simport
nnoremap \inc :call SetNewLine()<CR>S#include
nnoremap \ins :call SetNewLine()<CR>S#include <><Esc>i
nnoremap \de :call SetNewLine()<CR>S#define
function! SetNewLine()
if len(getline('.')) != 0
exec "normal! o"
endif
endfunction
nnoremap \main :call AddMain()<CR>o
function! AddMain()
if &filetype == 'c' || &filetype == 'cpp' || &filetype == 'h'
exec "normal! Iint main(int argc, char* argv[])\<CR>{\<CR>}\<ESC>k"
elseif &filetype == 'python'
exec "normal! Iif __name__ == '__main__':\<CR>\<Tab>main();\<Esc>kO\<Esc>O\<Esc>Idef main():"
elseif &filetype == 'java'
exec "normal! Spublic static void main(String[] args){\<CR>}\<ESC>k"
endif
endfunction
nnoremap \f :call AddFunc()<CR>i
function! AddFunc()
if &filetype == 'c' || &filetype == 'cpp' || &filetype == 'h'
exec "normal! S()\<CR>{\<CR>}\<ESC>kkI"
elseif &filetype == 'python'
exec "normal! Sdef ():\<ESC>$F("
elseif &filetype == 'java'
exec "normal! a(){\<CR>}\<ESC>k$F("
endif
endfunction
nnoremap \0f :call AddFrontFunc()<CR>i
function! AddFrontFunc()
if &filetype == 'c' || &filetype == 'cpp' || &filetype == 'h'
exec "normal! I()\<CR>{\<CR>}\<ESC>kkI"
elseif &filetype == 'python'
exec "normal! Idef ():\<ESC>$F("
elseif &filetype == 'java'
exec "normal! a(){\<CR>}\<ESC>k$F("
endif
endfunction
"函数调用
nnoremap \cf :call FunctionCall()<CR>F(i
function! FunctionCall()
if len(getline('.')) == 0
exec "normal! S();"
else
exec "normal! a();"
endif
endfunction
"切换C/C++相关联的头文件
nnoremap <F4> :call CPPAutoSwitch()<CR>
func CPPAutoSwitch()
if expand('%:e') == 'c'
let s:cpp_e = 'c'
call SwitchSourceAndHeader('c', 'h')
elseif expand('%:e') == 'cpp'
let s:cpp_e = 'cpp'
call SwitchSourceAndHeader('cpp', 'h')
elseif expand('%:e') == 'h'
if exists("s:cpp_e")
call SwitchSourceAndHeader(s:cpp_e, 'h')
elseif filereadable(expand('%:r').'.c')
call SwitchSourceAndHeader('c', 'h')
else
call SwitchSourceAndHeader('cpp', 'h')
endif
endif
endfunc
func SwitchSourceAndHeader(src, header)
if expand('%') == expand('%:r').'.'.a:src
let s:n = TabID(expand('%:r').'.'.a:header)
if(s:n == -1)
exec "tabe %<.".a:header
else
exec (s:n+1)."tabn"
endif
elseif expand('%') == expand('%:r').'.'.a:header
let s:n = TabID(expand('%:r').'.'.a:src)
if(s:n == -1)
exec "tabe %<.".a:src
else
exec (s:n+1)."tabn"
endif
endif
endfunc
func TabID(TabName)
for n in range(tabpagenr('$'))
if MyTabLabel(n+1) == a:TabName
return n
endif
endfor
return -1
endfunc
function MyTabLabel(n)
let buflist = tabpagebuflist(a:n)
let winnr = tabpagewinnr(a:n)
return bufname(buflist[winnr - 1])
endfunction
" 按F5编译
nnoremap <F5> :call CompileBuildGcc()<CR>
func! CompileBuildGcc()
exec "w"
if &filetype == 'c'
exec "!gcc -Wall % -o %<"
elseif &filetype == 'cpp'
exec "!g++ -Wall % -o %<"
elseif &filetype == 'rust'
exec "!rustc %"
elseif &filetype == 'java'
exec "!javac -encoding UTF-8 %"
elseif &filetype == 's'
exec "!gcc -o %< %<.s"
elseif &filetype == 'sh'
:!./%
elseif &filetype == 'asm'
if IsWindows()
exec "!nasm -f win32 % -o %<.o & gcc %<.o -o %<.exe"
else
exec "!nasm -f elf % -o %<"
endif
endif
endfunc
" 按F6运行
noremap <F6> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
if IsWindows()
if &filetype == 's' || &filetype == 'c' || &filetype == 'cpp' || &filetype == 'cc' || &filetype == 'rust' || &filetype == 'asm'
exec "! %<"
elseif &filetype == 'java'
exec "!java %<"
elseif &filetype == 'python'
exec "!python %"
elseif &filetype == 'sh'
! %
endif
else
if &filetype == 's' || &filetype == 'c' || &filetype == 'cpp' || &filetype == 'cc' || &filetype == 'rust' || &filetype == 'asm'
exec "! ./%<"
elseif &filetype == 'java'
exec "!java ./%<"
elseif &filetype == 'python'
exec "!python ./%"
elseif &filetype == 'sh'
! ./%
endif
endif
endfunc
" C,C++按F7调试
noremap <F7> :call Rungdb()<CR>
func! Rungdb()
exec "w"
if IsWindows()
if &filetype == 'c'
exec "!gcc -g % -o %<.exe"
elseif &filetype == 'cpp'
exec "!g++ -g % -o %<.exe"
endif
exec "!gdb ./%<.exe"
else
if &filetype == 'c'
exec "!gcc -g % -o %<"
elseif &filetype == 'cpp'
exec "!g++ -g % -o %<"
endif
exec "!gdb ./%<"
endif
endfunc
if g:EnablePlugin
"====================vimtex配置====================
let g:tex_flavor='latex'
"let g:vimtex_view_method='zathura'
let g:vimtex_quickfix_mode=0
set conceallevel=1
let g:tex_conceal='abdmg'
" \lx使用xelatex编译
" \lc删除临时文件
function ComplieWithXeTeX()
let oldRule = g:Tex_CompileRule_pdf
let g:Tex_CompileRule_pdf = 'latexmk --synctex=-1 -src-specials -interaction=nonstopmode $*'
call Tex_RunLaTeX()
let g:Tex_CompileRule_pdf = oldRule
endfunction
map <Leader>lx :<C-U>call ComplieWithXeTeX()<CR>
function CleanTempFiles()
execute '!latexmk -c'
endfunction
map <Leader>lc :<C-U>call CleanTempFiles()<CR>
" IMPORTANT: win32 users will need to have 'shellslash' set so that latex
" can be called correctly.
set shellslash
"====================tagbar配置====================
"设置tagbar使用的ctags的插件,必须要设置对
let g:tagbar_ctags_bin='ctags'
"设置tagbar的窗口宽度
let g:tagbar_width=26
"设置tagbar的窗口显示的位置到左边
let g:tagbar_right = 1
"设置标签不排序,默认排序
let g:tagbar_sort = 0
"打开文件自动打开
autocmd BufReadPost *.cpp,*.c,*.h,*.hpp,*.cc,*.cxx call tagbar#autoopen()
"映射tagbar的快捷键
map <silent> <F9> :TagbarToggle<CR>
"====================airline配置====================
" 这个是安装字体后 必须设置此项"
let g:airline_powerline_fonts = 1
" 打开tabline功能
let g:airline#extensions#tabline#enabled = 1
" 显示tab序号
let g:airline#extensions#tabline#tab_nr_type = 1
" 设置主题
let g:airline_theme="distinguished"
" 设置字体
if IsWindows()
set guifont=Noto_Mono_for_Powerline:h10
else
set guifont=Noto\ Mono\ for\ Powerline\ 11
endif
" 正常模式下TAB键切换Tabs
nnoremap <TAB> :tabn<CR>
nnoremap <S-TAB> :tabp<CR>
"====================NERDTree配置====================
""将F8设置为开关NERDTree的快捷键
map <F8> :NERDTreeToggle<cr>
""修改树的显示图标
" let g:NERDTreeDirArrowExpandable = '+'
" let g:NERDTreeDirArrowCollapsible = '-'
""窗口位置
let g:NERDTreeWinPos='left'
""窗口尺寸
let g:NERDTreeSize=30
" 新tab中打开文件
" let g:NERDTreeCustomOpenArgs = {'file': {'reuse': 'all', 'where': 't'}, 'dir': {}}
"====================CtrlP配置====================
" 防止按键冲突
let g:ctrlp_prompt_mappings = {'PrtClearCache()': ['<C-F5>'], 'PrtDeleteEnt()': ['<C-F7>']}
"====================需要Python支持的插件的配置====================
if has('python3')
"====================ultisnips配置====================
let g:UltiSnipsExpandTrigger = '<tab>'
let g:UltiSnipsJumpForwardTrigger = '<tab>'
let g:UltiSnipsJumpBackwardTrigger = '<s-tab>'
" 解决和YCM的按键冲突
function! g:UltiSnips_Complete()
call UltiSnips#ExpandSnippet()
if g:ulti_expand_res == 0
call UltiSnips#JumpForwards()
if g:ulti_jump_forwards_res == 0
return "\<TAB>"
endif
endif
return ""
endfunction
function! g:UltiSnips_Reverse()
call UltiSnips#JumpBackwards()
return ""
endfunction
if !exists("g:UltiSnipsJumpForwardTrigger")
let g:UltiSnipsJumpForwardTrigger = "<tab>"
endif
if !exists("g:UltiSnipsJumpBackwardTrigger")
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
endif
au InsertEnter * exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=g:UltiSnips_Complete()<cr>"
au InsertEnter * exec "inoremap <silent> " . g:UltiSnipsJumpBackwardTrigger . " <C-R>=g:UltiSnips_Reverse()<cr>"
"====================YCM配置====================
" 寻找全局配置文件
" 需要GCC支持且不需要clang支持
if IsWindows()
let g:ycm_global_ycm_extra_conf = '$VIM/vimfiles/bundle/YouCompleteMe/third_party/ycmd/.ycm_extra_conf.py'
else
let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/.ycm_extra_conf.py'
endif
" 禁用syntastic来对python检查
let g:syntastic_ignore_files=[".*\.py$"]
" 使用ctags生成的tags文件
let g:ycm_collect_identifiers_from_tag_files = 1
" 修改对C语言的补全快捷键,默认是CTRL+space,修改为ALT+/未测出效果
let g:ycm_key_invoke_completion = '<M-/>'
" 设置转到定义处的快捷键为ALT+G,未测出效果
"nmap <M-g> :YcmCompleter GoToDefinitionElseDeclaration <C-R>=expand("<cword>")<CR><CR>
"关键字补全
let g:ycm_seed_identifiers_with_syntax=1
" 在接受补全后不分裂出一个窗口显示接受的项
set completeopt-=preview
" 让补全行为与一般的IDE一致
set completeopt=longest,menu
" 不显示开启vim时检查ycm_extra_conf文件的信息
let g:ycm_confirm_extra_conf=0
" 每次重新生成匹配项,禁止缓存匹配项
let g:ycm_cache_omnifunc=0
" 在注释中也可以补全
let g:ycm_complete_in_comments=1
" 输入第一个字符就开始补全
let g:ycm_min_num_of_chars_for_completion=1
" 错误标识符
let g:ycm_error_symbol='E>'
" 警告标识符
let g:ycm_warning_symbol='W>'
" 不查询ultisnips提供的代码模板补全
let g:ycm_use_ultisnips_completer=0
endif
endif