-
Notifications
You must be signed in to change notification settings - Fork 0
/
zya_vimrc
606 lines (496 loc) · 16.8 KB
/
zya_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
" Vundle start--------
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim/
call vundle#rc()
" Bundle后的插件名来自于http://vim-scripts.org/vim/scripts.html的Name列
" Add all your plugins here
Plugin 'VundleVim/Vundle.vim'
" git submodule add https://github.com/Valloric/YouCompleteMe.git
" ~/.vim/bundle/YouCompleteMe
Plugin 'Valloric/YouCompleteMe'
" 折叠插件
Plugin 'tmhedberg/SimpylFold'
" 配色插件
Plugin 'jnurmine/Zenburn'
" 文件浏览,树形结构
Plugin 'scrooloose/nerdtree'
" 对上一个插件的补充,可用tab键
Plugin 'jistr/vim-nerdtree-tabs'
" 在vim中搜索任何文件
Plugin 'kien/ctrlp.vim'
" git插件
Plugin 'tpope/vim-fugitive'
Plugin 'airblade/vim-gitgutter'
" 工具栏
Plugin 'Lokaltog/vim-powerline'
" python代码检查flake8
Plugin 'nvie/vim-flake8'
" 语法检查
Plugin 'scrooloose/syntastic'
" 自动缩进符合PEP8标准
Plugin 'vim-scripts/indentpython.vim'
" 缩进指示线
Plugin 'Yggdroot/indentLine'
" 多行注释
Plugin 'scrooloose/nerdcommenter'
" python
Plugin 'python-mode/python-mode'
" Plugin 'altercation/vim-colors-solarized'
Plugin 'sjl/gundo.vim'
" 代码模板
Plugin 'SirVer/ultisnips'
Plugin 'honza/vim-snippets'
" 语法高亮
Plugin 'octol/vim-cpp-enhanced-highlight'
" 在cpp和h之间切换,替换a.vim"
Plugin 'derekwyatt/vim-fswitch'
" go
Plugin 'fatih/vim-go'
Plugin 'AndrewRadev/splitjoin.vim'
"颜色.
Plugin 'fatih/molokai'
"tagbar
Plugin 'majutsushi/tagbar'
"markdown支持.
"Plugin 'godlygeek/tabular'
"Plugin 'plasticboy/vim-markdown'
"Plugin 'iamcco/mathjax-support-for-mkdp'
"Plugin 'iamcco/markdown-preview.vim'
" json"
Plugin 'elzr/vim-json'
" All of your plugins must be added before the following line
call vundle#end()
filetype plugin indent on
" Vundle end----------
" 定义快捷键的前缀,即<Leader>
let mapleader=";"
" 设置快捷键将选中文本块复制至系统剪贴板
vnoremap <leader>y "+y
" 设置快捷键将系统剪贴板内容粘贴至VIM
nmap <leader>p "+p
" 定义快捷键关闭当前分割窗口
nmap <leader>q :q<CR>
" 定义快捷键保存当前窗口内容
nmap <leader>w :w<CR>
" 定义快捷键保存所有窗口内容并退出vim
nmap <leader>WQ :wa<CR>:q<CR>
" 不做任何保存,直接退出vim
nmap <leader>Q :qa!<CR>
" 依次遍历子窗口
nnoremap nw <C-W><C-W>
" 跳转至右方的窗口
nnoremap <leader>lw <C-W>l
" 跳转至左方的窗口
nnoremap <leader>hw <C-W>h
" 跳转至上方的窗口
nnoremap <leader>kw <C-W>k
" 跳转至下方的窗口
nnoremap <leader>jw <C-W>j
" 定义快捷键在结对符之间跳转,助记pair
nmap <leader>pa %
" 禁止光标闪烁
" set gcr=a:block-blinkon0
" 禁止显示滚动条
" set guioptions-=l
" set guioptions-=L
" set guioptions-=r
" set guioptions-=R
" 禁止显示菜单和工具条
" set guioptions-=m
" set guioptions-=T
" 开启语法高亮
syntax on
" 根据文件类型设置自动缩进
filetype indent plugin on
" 显示当前的行号列号
set ruler
" 在状态栏显示正在输入的命令
set showcmd
" vim自身命令行模式智能补全
set wildmenu
" 关闭/打开配对括号高亮
"NoMatchParen
"DoMatchParen
" 显示行号
set number
" 为方便起见,用F2开启/关闭行号显示
nnoremap <F2> :set nonumber!<CR>:set foldcolumn=0<CR>
" 启动modeline
set modeline
" 为深色背景调整配色
set background=dark
" 设置文件格式
set encoding=utf-8
set fileencoding=utf-8
" allow backspacing over everything in insert mode
set bs=indent,eol,start
" Tab宽度自动缩进字数
set ts=4
" 空格代替制表符
set expandtab
%retab!
" 设置格式化时制表符占用空格数
set shiftwidth=4
" 设置编辑时制表符占用空格数
set tabstop=4
" 自动缩进
set autoindent
set cindent
set smartindent
set t_Co=256
set nowrap
set history=500 "Keep 500 lines of command line history
" 总是显示状态行
set laststatus=2
" 距离顶部或底部5行
set scrolloff=5
" 禁止生成临时文件
set nobackup
set noswapfile
" 粘贴模式
:set pastetoggle=<F11>
" 突出显示当前行
set cursorline
" 突出显示当前列
set cursorcolumn
" 搜索忽略大小写
set ignorecase
" 搜索逐字符高亮
set hlsearch
set incsearch
" 新建文件时,自动插入文件头
autocmd BufNewFile *.py,*.cpp,*.[ch],*.hpp,*.sh,*.go exec ":call SetTitle()"
" 定义函数SetTitle,自动插入文件
func SetTitle()
if &filetype == 'sh'
call setline(1, "\#!/bin/bash")
call setline(2, "\##########################################")
call setline(3, "\# Copyright(c) ".strftime("%Y")." Shenzhen shenbaise9527")
call setline(4, "\# All Rights Reserved")
call setline(5, "\# @File : ".expand("%"))
call setline(6, "\# @Author : shenbaise9527")
call setline(7, "\# @Create : ".strftime("%Y-%m-%d %H:%M:%S"))
call setline(8, "\# @Modified : ".strftime("%Y-%m-%d %H:%M:%S"))
call setline(9, "\# @Description : ")
call setline(10, "\##########################################")
call setline(11, "")
call setline(12, "")
elseif &filetype == 'python'
call setline(1, "\#!/usr/bin/env python")
call setline(2, "\##########################################")
call setline(3, "\# Copyright(c) ".strftime("%Y")." Shenzhen shenbaise9527")
call setline(4, "\# All Rights Reserved")
call setline(5, "\# @File : ".expand("%"))
call setline(6, "\# @Author : shenbaise9527")
call setline(7, "\# @Create : ".strftime("%Y-%m-%d %H:%M:%S"))
call setline(8, "\# @Modified : ".strftime("%Y-%m-%d %H:%M:%S"))
call setline(9, "\# @Description : ")
call setline(10, "\##########################################")
call setline(11, "")
call setline(12, "")
elseif &filetype == 'go'
call setline(1, "\/**")
call setline(2, " * Copyright(c) ".strftime("%Y")." Shenzhen shenbaise9527")
call setline(3, " * All Rights Reserved")
call setline(4, " * @File : ".expand("%"))
call setline(5, " * @Author : shenbaise9527")
call setline(6, " * @Create : ".strftime("%Y-%m-%d %H:%M:%S"))
call setline(7, " * @Modified : ".strftime("%Y-%m-%d %H:%M:%S"))
call setline(8, " * @version : 1.0")
call setline(9, " * @Description : ")
call setline(10, " *\/")
call setline(11, "package main")
call setline(12, "")
call setline(13, "")
else
call setline(1, "\/**")
call setline(2, " * Copyright(c) ".strftime("%Y")." Shenzhen shenbaise9527")
call setline(3, " * All Rights Reserved")
call setline(4, " * @File : ".expand("%"))
call setline(5, " * @Author : shenbaise9527")
call setline(6, " * @Create : ".strftime("%Y-%m-%d %H:%M:%S"))
call setline(7, " * @Modified : ".strftime("%Y-%m-%d %H:%M:%S"))
call setline(8, " * @version : 1.0")
call setline(9, " * @Description : ")
call setline(10, " *\/")
call setline(11, "")
call setline(12, "")
endif
endfunc
" 新建文件后,自动定位到文件末尾
autocmd BufNewFile * normal G
autocmd FileWritePre,BufWritePre *.cpp,*.[ch],*.hpp,*.py,*.sh,*.go call DateModified()
func DateModified()
let zcur_line=line(".")
let zcur_clo=virtcol(".")
call cursor(1,1)
if search('@Modified')!=0
let line=line('.')
if line<9
if &filetype == 'sh'
call setline(line, "\# @Modified : ".strftime("%Y-%m-%d %H:%M:%S"))
elseif &filetype == 'python'
call setline(line, "\# @Modified : ".strftime("%Y-%m-%d %H:%M:%S"))
else
call setline(line, " * @Modified : ".strftime("%Y-%m-%d %H:%M:%S"))
endif
endif
endif
call cursor(zcur_line,zcur_clo)
endfunc
map <F10> :call SetTitle()<CR>
" 打开文件类型检测,加了这句才可以用智能补全
set completeopt=menu,menuone,longest
"Fast reloading of the .vimrc
"map <silent><leader> ss:source ~/.vimrc<cr>
"Fast editing of .vimrc
"map <silent><leader> ee:e ~/.vimrc<cr>
"when .vimrc is edited,reload it
"autocmd! bufwritepost .vimrc source ~/.vimrc
set showmatch
" 当文件被改动时自动载入
set autoread
" 自动完成括号和引号
:inoremap ( ()<ESC>i
:inoremap ) <c-r>=ClosePair(')')<CR>
:inoremap { {<CR>}<ESC>o
:inoremap } <c-r>=ClosePair('}')<CR>
:inoremap [ []<ESC>i
:inoremap ] <c-r>=ClosePair(']')<CR>
:inoremap " ""<ESC>i
:inoremap ' ''<ESC>i
function! ClosePair(char)
if getline('.')[col('.')-1] == a:char
return "\<Right>"
else
return a:char
endif
endfunction
" 行字符数超过120就把字符的背景设置为红色
highlight OverLength ctermbg=red ctermfg=white guibg=#592929
match OverLength /\%121v.\+/
" 标示不必要的空白字符,autocmd可以缩写为au
" au BufRead,BufNewFile *.py,*.pyw,*.c,*.h match BadWhitespace /\s\+$/
" winmanager
"let g:winManagerWindowLayout='TagList'
"let g:winManagerWidth=30
nmap <C-W><C-F> :FirstExplorerWindow<CR>
nmap <C-W><C-B> :BottomExplorerWindow<CR>
"nmap wm :WMToggle<CR>
nmap wm :TagbarToggle<CR>
"设置宽度.
let g:tagbar_width=30
"let g:tagbar_autofocus=1
"let g:tagbar_autoclose=1
" 自动打开.
autocmd BufReadPost *.cpp,*.c,*.h,*.hpp,*.cc,*.go call tagbar#autoopen()
" 控制编译错误时quickfix窗口在最底部"
autocmd FileType qf wincmd J
" 控制quickfix窗口向上向下移动"
map <C-n> :cnext<CR>
map <C-m> :cprevious<CR>
nnoremap <leader>a :cclose<CR>
" minibuferpl.vim for top buff list
let g:miniBufExplMapWindowNavVim=1
" .cpp和.h之间切换
nmap <silent><leader>sw :FSHere<CR>
" 配色
"colors zenburn
colorscheme molokai
let g:molokai_original = 1
" NERDTree
map <F3> :NERDTreeMirror<CR>
map <F3> :NERDTreeToggle<CR>
"let g:NERDTreeWinPos="right"
let g:NERDTreeWinPos="left"
let g:NERDTreeWinSize=25
let g:NERDTreeShowLineNumbers=1
let g:neocomplcache_enable_at_startup=1
let NERDTreeIgnore=['\~$', '\.pyc$', '\.swp$']
" 显示隐藏文件
" let g:NERDTreeShowHidden=1
" 子窗口不显示冗余帮助信息
let g:NERDTreeMinimalUI=1
" 删除文件时自动删除文件对应的buffer
let g:NERDTreeAutoDeleteBuffer=1
" o 打开关闭文件或者目录
" t 在标签页中打开
" T 在后台标签页中打开
" ! 执行此文件
" p 到上层目录
" P 到根目录
" K 到第一个节点
" J 到最后一个节点
" u 打开上层目录
" m 显示文件系统菜单(添加、删除、移动操作)
" ? 帮助
" q 关闭
" I 切换是否显示隐藏文件
" F 切换是否显示文件
" B 切换是否显示书签
" f 切换是否使用文件过滤器
" R 递归刷新根结点
" r 递归刷新选中目录
" map <leader>n <plug>NERDTreeTabsToggle<CR>
" let g:nerdtree_tabs_open_on_console_startup=1
" nerdcommenter命令
" ;cc 注释当前行和选中行
" ;cn 没有发现和cc有区别
" ;c<空格>
" 如果被选区域有部分被注释,则对被选区域执行取消注释操作,其它情况执行反转注释操作
" ;cm 对被选区域用一对注释符进行注释,前面的注释对每一行都会添加注释
" ;ci 执行反转注释操作,选中区域注释部分取消注释,非注释部分添加注释
" ;cs 添加性感的注释,代码开头介绍部分通常使用该注释
" ;cy 添加注释,并复制被添加注释的部分
" ;c$ 注释当前光标到该行结尾的内容
" ;cA 跳转到该行结尾添加注释,并进入编辑模式
" ;ca 转换注释的方式,比如:/**/和//
" ;cl ;cb 左对齐和左右对齐,左右对齐主要针对/**/
" ;cu 取消注释
" 基于语法或缩进进行代码折叠
" set foldmethod=indent
set foldmethod=syntax
" 启动vim时关闭折叠
set nofoldenable
" 默认展开所有代码
set foldlevel=99
" 看到折叠代码的文档字符串
let g:SimpylFold_docstring_preview=1
" press space to fold/unfold code
nnoremap <space> za
vnoremap <space> zf
" powerline begin----
let g:Powerline_colorscheme='solarized256'
" let g:Powerline_symbols='fancy'
set t_Co=256
let Powerline_symbols='compatible'
" powerline end----
" gundo show undo window
nnoremap <leader>ud :GundoToggle<CR>
" let g:gundo_width=60
" let g:gundo_preview_height=40
let g:gundo_right=1
" Ctrlp
nnoremap <leader>ff :CtrlP<CR>
" 缩进指示线
let g:indentLine_char='┆'
" let g:indentLine_char='|'
let g:indentLine_enabled=1
" let g:indentLine_concealcursor='inc'
" let g:indentLine_concealleavel=2
" vim-go custom mappings
au FileType go nmap <leader>s <Plug>(go-implements)
au FileType go nmap <leader>i <Plug>(go-info)
au FileType go nmap <leader>gd <Plug>(go-doc)
au FileType go nmap <leader>gv <Plug>(go-doc-vertical)
au FileType go nmap <leader>r <Plug>(go-run)
au FileType go nmap <leader>b <Plug>(go-build)
au FileType go nmap <leader>t <Plug>(go-test)
au FileType go nmap <leader>c <Plug>(go-coverage)
au FileType go nmap <leader>ds <Plug>(go-def-split)
au FileType go nmap <leader>dv <Plug>(go-def-vertical)
au FileType go nmap <leader>dt <Plug>(go-def-tab)
au FileType go nmap <leader>e <Plug>(go-rename)
au FileType go nmap <leader>gr <Plug>(go-referrers)
"vim-go settings
let g:go_fmt_command = "goimports"
" 高亮类型
let g:go_highlight_types = 1
" 高亮属性字段
let g:go_highlight_fields = 1
let g:go_highlight_functions = 1
let g:go_highlight_function_calls = 1
" 高亮操作符.
let g:go_highlight_operators = 1
" 高亮额外的类型.
let g:go_highlight_extra_types = 1
" 注释掉代码vim-go/autoload/go/template.vim,L22-28"
"----YCM begin----
" "set runtimepath+=~/.vim/bundle/YouCompleteMe
" 开启YCM基于标签引擎
let g:ycm_collect_identifiers_from_tags_files=1
" 注释与字符串中的内容也用于补全
let g:ycm_collect_identifiers_from_comments_and_strings=1
let g:syntastic_ignore_files=[".*\.py$"]
" 语法关键字补全
let g:ycm_seed_identifiers_with_syntax=1
let g:ycm_complete_in_comments=1
let g:ycm_confirm_extra_conf=0
" 映射按键,没有这个会拦截掉TAB,导致其它插件的TAB不可用
let g:ycm_key_list_select_completion=['<c-n>', '<Down']
let g:ycm_key_list_previous_completion=['<c-p>', '<Up']
" 在注释输入中也能补全
let g:ycm_complete_in_comments=1
" 在字符串输入中也能补全
let g:ycm_complete_in_strings=1
"let g:ycm_global_ycm_extra_conf='~/.vim/.ycm_extra_conf.py'
let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/third_party/ycmd/.ycm_extra_conf.py'
" 禁用语法检查
let g:ycm_show_diagnostics_ui=0
" python解释器路径
let g:ycm_path_to_python_interpreter='/usr/bin/python3'
" 从第二个键入字符就开始罗列匹配项
let g:ycm_min_num_of_chars_for_completion=2
" 补全后自动关闭预览窗口
let g:ycm_autoclose_preview_window_after_completion=1
" 禁止匹配缓存项,每次都重新生成缓存项
let g:ycm_cache_omnifunc=0
" 离开插入模式后自动关闭预览窗口
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
" 回车即选中当前项
inoremap <expr> <CR> pumvisible() ? '<C-y>' : '<CR>'
" 上下左右键行为
inoremap <expr> <Down> pumvisible() ? '\<C-n>' : '\<Down>'
inoremap <expr> <Up> pumvisible() ? '\<C-p>' : '\<Up>'
nnoremap <leader>yd :YcmCompleter GoToDeclaration<CR>
nnoremap <leader>yf :YcmCompleter GoToDefinition<CR>
" 跳转到定义处
nnoremap <leader>yg :YcmCompleter GoToDefinitionElseDeclaration<CR>
" show error
nnoremap <leader>ye :YcmDiags<CR>
" force to recompile files
nnoremap <leader>yr :YcmForceCompileAndDiagnostics<CR>
let g:ycm_semantic_triggers = {'python,go': ['re!\w{2}'],}
" ----YCM end----
" Highlighting of class scope is disabled by default. To enable set
let g:cpp_class_scope_highlight = 1
" Highlighting of member variables is disabled by default. To enable set
let g:cpp_member_variable_highlight = 1
" hightlight template functions.
let g:cpp_experimental_simple_template_highlight = 1
" which works in most cases, but can be a little slow on large files. Alternatively set
" let g:cpp_experimental_template_highlight = 1
" which is a faster implementation but has some corner cases where it doesn't work.
" Highlighting of library concepts is enabled by
let g:cpp_concepts_highlight = 1
" ----json----
let g:vim_json_syntax_conceal = 0
" ----python----
" python文件中建议用空格代替TAB,且缩进应为4个空格
autocmd FileType python setlocal et sta sw=4 sts=4
" 支持PEP8风格的缩进
" au BufNewFile,BufRead *.py
"" \ set tabstop=4
"" \ set softtabstop=4
"" \ set shiftwidth=4
"" \ set textwidth=79
"" \ set expandtab
"" \ set autoindent
"" \ set fileformat=unix
" 代码折叠可以只以缩进为依据:
autocmd FileType python setlocal foldmethod=indent
let python_highlight_all = 1
" 按F5运行python
map <F5> :call RunPython()<CR>
function RunPython()
let mp = &makeprg
let ef = &errorformat
let exeFile = expand("%:t")
setlocal makeprg=python\ -u
set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
silent make %
copen
let &makeprg = mp
let &errorformat = ef
endfunction