-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
410 lines (346 loc) · 14.4 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
" -----------------------------------------------------------------------------
" < 判断操作系统是否是 Windows 还是 Linux >
" -----------------------------------------------------------------------------
let mapleader=","
let g:iswindows = 0
let g:islinux = 0
if(has("win32") || has("win64") || has("win95") || has("win16"))
let g:iswindows = 1
else
let g:islinux = 1
endif
" -----------------------------------------------------------------------------
" < 判断是终端还是 Gvim >
" -----------------------------------------------------------------------------
if has("gui_running")
let g:isGUI = 1
else
let g:isGUI = 0
endif
" -----------------------------------------------------------------------------
" < Windows Gvim 默认配置> 做了一点修改
" -----------------------------------------------------------------------------
if (g:iswindows && g:isGUI)
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin
set diffexpr=MyDiff()
function MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
let eq = ''
if $VIMRUNTIME =~ ' '
if &sh =~ '\<cmd'
let cmd = '""' . $VIMRUNTIME . '\diff"'
let eq = '"'
else
let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
endif
else
let cmd = $VIMRUNTIME . '\diff'
endif
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction
endif
" -----------------------------------------------------------------------------
" < Linux Gvim/Vim 默认配置> 做了一点修改
" -----------------------------------------------------------------------------
if g:islinux
set hlsearch "高亮搜索
set incsearch "在输入要搜索的文字时,实时匹配
" Uncomment the following to have Vim jump to the last position when
" reopening a file
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif
if g:isGUI
" Source a global configuration file if available
if filereadable("/etc/vim/gvimrc.local")
source /etc/vim/gvimrc.local
endif
else
" This line should not be removed as it ensures that various options are
" properly set to work with the Vim-related packages available in Debian.
runtime! debian.vim
" Vim5 and later versions support syntax highlighting. Uncommenting the next
" line enables syntax highlighting by default.
if has("syntax")
syntax on
endif
set mouse-=a " 在任何模式下启用鼠标
set t_Co=256 " 在终端启用256色
set backspace=2 " 设置退格键可用
" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
source /etc/vim/vimrc.local
endif
endif
endif
" -----------------------------------------------------------------------------
" < Vundle 插件管理工具配置 >
" -----------------------------------------------------------------------------
" 用于更方便的管理vim插件,具体用法参考 :h vundle 帮助
" 安装方法为在终端输入如下命令
" git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
" 如果想在 windows 安装就必需先安装 "git for window",可查阅网上资料
set nocompatible "禁用 Vi 兼容模式
filetype off "禁用文件类型侦测
if g:islinux
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
else
set rtp+=$VIM/vimfiles/bundle/vundle/
call vundle#rc('$VIM/vimfiles/bundle/')
endif
" 使用Vundle来管理Vundle,这个必须要有。
Bundle 'gmarik/vundle'
filetype plugin indent on
"********************************************
Bundle 'The-NERD-tree'
Bundle 'jistr/vim-nerdtree-tabs'
let g:nerdtree_tabs_open_on_gui_startup=1 "设置打开vim的时候默认打开目录树
map <leader>t <plug>NERDTreeTabsToggle <CR> "设置打开目录树的快捷键
"********************************************
Bundle 'tpope/vim-commentary'
nmap <BS> gcc
vmap <BS> gc
"********************************************
Bundle 'mattn/webapi-vim'
Bundle 'mattn/gist-vim'
"********************************************
"两种不错的配色方案,都可以
Bundle 'chriskempson/tomorrow-theme'
Bundle 'sickill/vim-monokai'
"********************************************
Bundle 'Pydiction'
if g:islinux
let g:pydiction_location = '/home/jasonsun/.vim/bundle/Pydiction/complete-dict'
else
let g:pydiction_location = 'D:\Program Files\Vim\vimfiles\bundle\Pydiction\complete-dict'
endif
"********************************************
Bundle 'dimasg/vim-mark'
set viminfo+=!
"********************************************
Bundle 'jmcantrell/vim-virtualenv'
"Bundle 'klen/python-mode'
"********************************************
Bundle 'Lokaltog/powerline'
"********************************************
Bundle 'mattn/emmet-vim'
"********************************************
Bundle 'msanders/snipmate.vim'
imap <C-J> <Plug>snipMateNextOrTrigger
smap <C-J> <Plug>snipMateNextOrTrigger
"********************************************
Bundle 'kien/ctrlp.vim'
Bundle 'tacahiroy/ctrlp-funky'
let g:ctrlp_extensions = ['funk']
"********************************************
"Bundle 'taglist.vim'
"********************************************
Bundle 'majutsushi/tagbar'
Bundle 'fholgado/minibufexpl.vim'
Bundle 'mileszs/ack.vim'
" Bundle 'bling/vim-airline'
Bundle 'Lokaltog/vim-easymotion'
Bundle 'altercation/vim-colors-solarized'
Bundle 'grin.vim'
Bundle 'benmills/vimux'
Bundle 'skammer/vim-css-color'
Bundle 'scrooloose/syntastic'
" -----------------------------------------------------------------------------
" < 编码配置 >
" -----------------------------------------------------------------------------
" 注:使用utf-8格式后,软件与程序源码、文件路径不能有中文,否则报错
set encoding=utf-8 "设置gvim内部编码
set fileencoding=utf-8 "设置当前文件编码
set fileencodings=ucs-bom,utf-8,gbk,cp936,latin-1 "设置支持打开的文件的编码
" 文件格式,默认 ffs=dos,unix
set fileformat=unix "设置新文件的<EOL>格式
set fileformats=unix,dos,mac "给出文件的<EOL>格式类型
if (g:iswindows && g:isGUI)
"解决菜单乱码
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
"解决consle输出乱码
language messages zh_CN.utf-8
endif
" -----------------------------------------------------------------------------
" < 编写文件时的配置 >
" -----------------------------------------------------------------------------
filetype on "启用文件类型侦测
filetype plugin on "针对不同的文件类型加载对应的插件
filetype plugin indent on "启用缩进
set smartindent "启用智能对齐方式
set expandtab "将Tab键转换为空格
set tabstop=4 "设置Tab键的宽度
set shiftwidth=4 "换行时自动缩进4个空格
set smarttab "指定按一次backspace就删除shiftwidth宽度的空格
set foldenable "启用折叠
set foldmethod=indent "indent 折叠方式
set foldmethod=marker "marker 折叠方式
" 用空格键来开关折叠
nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>
" 当文件在外部被修改,自动更新该文件
set autoread
" 常规模式下输入 cS 清除行尾空格
nmap cS :%s/\s\+$//g<CR>:noh<CR>
" 常规模式下输入 cM 清除行尾 ^M 符号
nmap cM :%s/\r$//g<CR>:noh<CR>
set ignorecase "搜索模式里忽略大小写
set smartcase "如果搜索模式包含大写字符,不使用 'ignorecase' 选项,只有在输入搜索模式并且打开 'ignorecase' 选项时才会使用
" set noincsearch "在输入要搜索的文字时,取消实时匹配
" key mapping how to siwtch between buffers
map <Leader>a :bprev<Return>
map <Leader>s :bnext<Return>
map <Leader>d :bd<Return>
"map <Leader>t <C-p>
imap <A-1> <Esc>:buffer 1<CR>i
imap <A-2> <Esc>:buffer 2<CR>i
imap <A-3> <Esc>:buffer 3<CR>i
imap <A-4> <Esc>:buffer 4<CR>i
imap <A-5> <Esc>:buffer 5<CR>i
imap <A-6> <Esc>:buffer 6<CR>i
imap <A-7> <Esc>:buffer 7<CR>i
imap <A-8> <Esc>:buffer 8<CR>i
imap <A-9> <Esc>:buffer 9<CR>i
map <A-1> :buffer 1<CR>
map <A-2> :buffer 2<CR>
map <A-3> :buffer 3<CR>
map <A-4> :buffer 4<CR>
map <A-5> :buffer 5<CR>
map <A-6> :buffer 6<CR>
map <A-7> :buffer 7<CR>
map <A-8> :buffer 8<CR>
map <A-9> :buffer 9<CR>
" Map ctrl-movement keys to window switching
map <C-k> <C-w><Up>
map <C-j> <C-w><Down>
map <C-l> <C-w><Right>
map <C-h> <C-w><Left>
" " Ctrl + K 插入模式下光标向上移动
" imap <c-k> <Up>
" " Ctrl + J 插入模式下光标向下移动
" imap <c-j> <Down>
" " Ctrl + H 插入模式下光标向左移动
" imap <c-h> <Left>
" " Ctrl + L 插入模式下光标向右移动
" imap <c-l> <Right>
" 启用每行超过80列的字符提示(字体变蓝并加下划线),不启用就注释掉
"au BufWinEnter * let w:m2=matchadd('Underlined', '\%>' . 80 . 'v.\+', -1)
" -----------------------------------------------------------------------------
" < 界面配置 >
" -----------------------------------------------------------------------------
set number "显示行号
set laststatus=2 "启用状态栏信息
"set cmdheight=1 "设置命令行高度为2,默认为1
set cursorline "突出显示当前行
set guifont=Consolas:h12 "设置字体:字号(字体名称空格用下划线代替)
set nowrap "设置不自动换行
set shortmess=atI "去掉欢迎界面
" 设置 gVim 窗口初始位置及大小
if g:isGUI
" au GUIEnter * simalt ~x "窗口启动时自动最大化
winpos 100 10 "指定窗口出现的位置,坐标原点在屏幕左上角
set lines=38 columns=120 "指定窗口大小,lines为高度,columns为宽度
endif
" 设置代码配色方案
if g:isGUI
" colorscheme Tomorrow-Night-Eighties "Gvim配色方案
"colorscheme monokai
colorscheme jellybeans
else
colorscheme monokai
"colorscheme Tomorrow-Night-Eighties "终端配色方案
endif
" 显示/隐藏菜单栏、工具栏、滚动条,可用 Ctrl + F11 切换
if g:isGUI
set guioptions-=m
set guioptions-=T
"set guioptions-=r
set guioptions-=L
map <silent> <c-F11> :if &guioptions =~# 'm' <Bar>
\set guioptions-=m <Bar>
\set guioptions-=T <Bar>
" \set guioptions-=r <Bar>
\set guioptions-=L <Bar>
\else <Bar>
\set guioptions+=m <Bar>
\set guioptions+=T <Bar>
" \set guioptions+=r <Bar>
\set guioptions+=L <Bar>
\endif<CR>
endif
map <F12> :call Do_CsTag()<CR>
nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>:copen<CR>
nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>:copen<CR>
nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>:copen<CR>
nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>:copen<CR>
nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR>:copen<CR>
nmap <C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>:copen<CR>
nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>:copen<CR>
function Do_CsTag()
let dir = getcwd()
if filereadable("tags")
if(g:iswindows==1)
let tagsdeleted=delete(dir."\\"."tags")
else
let tagsdeleted=delete("./"."tags")
endif
if(tagsdeleted!=0)
echohl WarningMsg | echo "Fail to do tags! I cannot delete the tags" | echohl None
return
endif
endif
if has("cscope")
silent! execute "cs kill -1"
endif
if filereadable("cscope.files")
if(g:iswindows==1)
let csfilesdeleted=delete(dir."\\"."cscope.files")
else
let csfilesdeleted=delete("./"."cscope.files")
endif
if(csfilesdeleted!=0)
echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.files" | echohl None
return
endif
endif
if filereadable("cscope.out")
if(g:iswindows==1)
let csoutdeleted=delete(dir."\\"."cscope.out")
else
let csoutdeleted=delete("./"."cscope.out")
endif
if(csoutdeleted!=0)
echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.out" | echohl None
return
endif
endif
if(executable('ctags'))
"silent! execute "!ctags -R --c-types=+p --fields=+S *"
silent! execute "!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q ."
endif
if(executable('cscope') && has("cscope") )
if(g:iswindows!=1)
silent! execute "!find . -name '*.h' -o -name '*.c' -o -name '*.cpp' -o -name '*.java' -o -name '*.cs' > cscope.files"
else
silent! execute "!dir /s/b *.c,*.cc,*.hh,*.hpp,*.cpp,*.h,*.java,*.cs >> cscope.files"
endif
silent! execute "!cscope -b"
execute "normal :"
if filereadable("cscope.out")
execute "cs add cscope.out"
endif
endif
endfunction
set backspace=indent,eol,start