-
Notifications
You must be signed in to change notification settings - Fork 20
/
_vimrc
432 lines (344 loc) · 10.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
" 永远的冰点的VIM配置件
" 2011/12/17
" http://wlog.cn
if v:version < 700
echoerr 'This _vimrc requires Vim 7 or later.'
quit
endif
" 设置菜单语言
set langmenu=zh_cn
" =========
" 功能函数
" =========
" 获取当前目录
func GetPWD()
return substitute(getcwd(), "", "", "g")
endf
" =========
" 环境配置
" =========
" 保留历史记录
set history=600
" 命令行于状态行
set ch=1
set stl=\ [File]\ %F%m%r%h%y[%{&fileformat},%{&fileencoding}]\ %w\ \ [PWD]\ %r%{GetPWD()}%h\ %=\ [Line]\ %l,%c\ %=\ %P
set ls=2 "始终显示状态行
" 状态栏显示目前所执行的指令
set showcmd
" 控制台响铃(关闭遇到错误时的声音提示)
:set noerrorbells
:set novisualbell
:set t_vb= "close visual bell
" 行控制
set linebreak "英文单词在换行时不被截断
set nocompatible "设置不兼容VI
set textwidth=80 "设置每行80个字符自动换行,加上换行符
set wrap "设置自动折行
" 缩进
set autoindent "设置自动缩进
set smartindent "设置智能缩进
" 行号和标尺
set number "行号
set ruler "在右下角显示光标位置的状态行
set rulerformat=%15(%c%V\ %p%%%)
" 标签页
set tabpagemax=20 "最多20个标签
set showtabline=2 "总是显示标签栏
" tab转化为4个字符
set tabstop=4
set expandtab
set smarttab
set shiftwidth=4
set softtabstop=4
"设置行高
set linespace=4
" 插入模式下使用 <BS>、<Del> <C-W> <C-U>
set backspace=indent,eol,start
" 自动重新读入
set autoread
" 自动改变当前目录
if has('netbeans_intg')
set autochdir
endif
"搜索
set ignorecase "在查找时忽略大小写
set incsearch "关闭显示查找匹配过程
set hlsearch "高亮显示搜索的内容
" 显示匹配的括号
" set showmatch
" 匹配配对的字符
func! MatchingQuotes()
inoremap ( ()<left>
inoremap [ []<left>
inoremap { {}<left>
inoremap " ""<left>
inoremap ' ''<left>
endf
" 在所有模式下都允许使用鼠标,还可以是n,v,i,c等
set mouse=a
" 恢复上次文件打开位置
set viminfo='10,\"100,:20,%,n~/.viminfo
au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif
" Diff 模式的时候鼠标同步滚动 for Vim7.3
if has('cursorbind')
set cursorbind
end
" =====================
" 多语言环境
" 默认为 UTF-8 编码
" =====================
if has("multi_byte")
set encoding=utf-8
" English messages only
"language messages zh_CN.utf-8
if has('win32')
language english
let &termencoding=&encoding
endif
set fencs=utf-8,gbk,chinese,latin1
set formatoptions+=mM
set nobomb " 不使用 Unicode 签名
if v:lang =~? '^\(zh\)\|\(ja\)\|\(ko\)'
set ambiwidth=double
endif
else
echoerr "Sorry, this version of (g)vim was not compiled with +multi_byte"
endif
filetype plugin indent on "打开文件类型检测
" :help mbyte-IME
if has('multi_byte_ime')
highlight Cursor guibg=#F0E68C guifg=#708090
highlight CursorIM guibg=Purple guifg=NONE
endif
" =====================
" AutoCmd 自动运行
" =====================
if has("autocmd")
" 括号自动补全
func! AutoClose()
:inoremap ( ()<ESC>i
:inoremap " ""<ESC>i
:inoremap ' ''<ESC>i
:inoremap { {}<ESC>i
:inoremap [ []<ESC>i
:inoremap ) <c-r>=ClosePair(')')<CR>
:inoremap } <c-r>=ClosePair('}')<CR>
:inoremap ] <c-r>=ClosePair(']')<CR>
endf
func! ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endf
augroup vimrcEx "记住上次文件位置
au!
autocmd FileType text setlocal textwidth=80
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
augroup END
" Auto close quotation marks for PHP, Javascript, etc, file
au FileType php,javascript exe AutoClose()
au FileType php,javascript exe MatchingQuotes()
" Auto Check Syntax
" au BufWritePost,FileWritePost *.js,*.php call CheckSyntax(1)
" JavaScript 语法高亮
au FileType html,javascript let g:javascript_enable_domhtmlcss = 1
au BufRead,BufNewFile *.js setf jquery
" 打开javascript对dom、html和css的支持
let javascript_enable_domhtmlcss=1
" 给各语言文件添加 Dict
if has('win32')
let s:dict_dir = $VIM.'\vimfiles\dict\'
else
let s:dict_dir = $HOME."/.vim/dict/"
endif
let s:dict_dir = "setlocal dict+=".s:dict_dir
au FileType php exec s:dict_dir."php_funclist.dict"
au FileType css exec s:dict_dir."css.dict"
au FileType javascript exec s:dict_dir."javascript.dict"
" 增加 ActionScript 语法支持
au BufNewFile,BufRead,BufEnter,WinEnter,FileType *.as setf actionscript
" CSS3 语法支持
au BufRead,BufNewFile *.css set ft=css syntax=css3
" 增加 Objective-C 语法支持
au BufNewFile,BufRead,BufEnter,WinEnter,FileType *.m,*.h setf objc
" 将指定文件的换行符转换成 UNIX 格式
au FileType php,javascript,html,css,python,vim,vimwiki set ff=unix
" 保存编辑状态
au BufWinLeave * if expand('%') != '' && &buftype == '' | mkview | endif
au BufRead * if expand('%') != '' && &buftype == '' | silent loadview | syntax on | endif
endif
" =========
" 图形界面
" =========
if has('gui_running')
" 只显示菜单
set guioptions=mcr
" 高亮光标所在的行
set cursorline
" 编辑器配色
"colorscheme zenburn
"colorscheme dusk
"colorscheme breeze
"colorscheme molokai
set background=light "for solarized
colorscheme solarized
if has("win32")
" Windows 兼容配置
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
" f11 最大化 /vimfiles/extra/fullscreen/gvimfullscreen.dll移动到安装目录
"nmap <f11> :call libcallnr('gvimfullscreen.dll', 'ToggleFullScreen', 0)<cr>
"nmap <Leader><Leader> :call libcallnr('gvimfullscreen.dll', 'ToggleFullScreen', 0)<cr>
" 自动最大化窗口
au GUIEnter * simalt ~x
" 给 Win32 下的 gVim 窗口设置透明度 http://www.vim.org/scripts/script.php?script_id=687
"/vimfiles/extra/vimtweak/vimtweak.dll移动到安装目录
" au GUIEnter * call libcallnr("vimtweak.dll", "SetAlpha", 250)
" 字体配置
"http://support.microsoft.com/kb/306527/zh-cn
"set guifont=Droid\ Sans\ Mono:h10.5:cANSI
"set guifontwide=YouYuan:h10.5:cGB2312
"cygwin路径
"set shell=d:\cygwin\bin\mintty.exe\ -
endif
" Under Mac
if has("gui_macvim")
"开启抗锯齿渲染
set anti
" MacVim 下的字体配置
"set guifont=Courier_New:h14
"set guifontwide=YouYuan:h14
"set guifontwide=Microsoft\ Yahei\ Mono:h14
"set guifontwide=YouYuan:h13
"set guifontwide=YouYuan:h14
"set guifont=Droid\ Sans\ Mono:h14
"set guifontwide=Yahei_Mono:h14
set guifont=Monaco:h14
set guifontwide=YouYuan:h14
" 半透明和窗口大小
set transparency=2
set lines=300 columns=120
" 使用 MacVim 原生的全屏幕功能
let s:lines=&lines
let s:columns=&columns
func! FullScreenEnter()
set lines=999 columns=999
set fu
endf
func! FullScreenLeave()
let &lines=s:lines
let &columns=s:columns
set nofu
endf
func! FullScreenToggle()
if &fullscreen
call FullScreenLeave()
else
call FullScreenEnter()
endif
endf
set guioptions+=e
" Mac 下,按 \\ 切换全屏
nmap <f11> :call FullScreenToggle()<cr>
nmap <Leader><Leader> :call FullScreenToggle()<cr>
" I like TCSH :^)
set shell=/bin/tcsh
" Set input method off
set imdisable
" Set QuickTemplatePath
let g:QuickTemplatePath = $HOME.'/.vim/templates/'
" 如果为空文件,则自动设置当前目录为桌面
lcd ~/Desktop/
endif
" Under Linux/Unix etc.
if has("unix") && !has('gui_macvim')
set guifont=Courier\ 10\ Pitch\ 11
endif
endif
" JSLint.vim
if has("win32")
let g:jslint_command = $VIMFILES . '/extra/jsl/win/jsl.exe'
else
let g:jslint_command = $VIMFILES . '/extra/jsl/mac/jsl'
endif
let g:jslint_highlight_color = '#996600'
"let g:jslint_command_options = '-conf ' . $VIMFILES . '/extra/jsl/jsl.conf -nofilelisting -nocontext -nosummary -nologo -process'
"let g:jslint_command_options = '-nofilelisting -nocontext -nosummary -nologo -process'
" =========
" 插件
" =========
" Calendar
" http://www.vim.org/scripts/script.php?script_id=52
if has("gui_macvim")
let g:calendar_diary=$HOME.'/.vim/diary/'
endif
map cal :Calendar<cr>
" NERDTree
" http://www.vim.org/scripts/script.php?script_id=1658
let NERDTreeWinSize=22
map ntree :NERDTree <cr>
map nk :NERDTreeClose <cr>
map <leader>n :NERDTreeToggle<cr>
" 新建 XHTML 、PHP、Javascript 文件的快捷键
nmap <C-c><C-h> :NewQuickTemplateTab xhtml<cr>
nmap <C-c><C-g> :NewQuickTemplateTab html<cr>
nmap <C-c><C-p> :NewQuickTemplateTab php<cr>
nmap <C-c><C-j> :NewQuickTemplateTab javascript<cr>
nmap <C-c><C-c> :NewQuickTemplateTab css<cr>
" jsbeauty
"http://www.vim.org/scripts/script.php?script_id=2727
" \ff
" =========
" 快捷键
" =========
" 标签相关的快捷键 Ctrl
map tn :tabnext<cr>
map tp :tabprevious<cr>
map tc :tabclose<cr>
map <C-n> :tabnew<cr>
map <C-Tab> :tabnext<cr>
"最近打开的文件
nmap <Leader>mr :MRU<cr>
"字体大小
"http://www.vim.org/scripts/script.php?script_id=2809
"<Leader>== Begin "font size" mode
"<Leader>++ Increment font size
"<Leader>-- Decrement font size
"<Leader>00 Revert to default font size
" 在文件名上按gf时,在新的tab中打开
map gf :tabnew <cfile><cr>
" 返回当前时间
func! GetTimeInfo()
"return strftime('%Y-%m-%d %H:%M:%S')
return strftime('%Y-%m-%d')
endfunction
" 插入模式按 Ctrl + D(ate) 插入当前时间
imap <C-d> <C-r>=GetTimeInfo()<cr>
"F12启动firefox
if has("win32")
map <F12> :silent! !"C:\Program Files\Mozilla Firefox\firefox.exe" % <CR>
endif
"zen-coding,(c+y+,)
let g:user_zen_expandabbr_key = '<c-e>'
let g:use_zen_complete_tag = 1
" 保证语法高亮
syntax on
" =========
" 帮助
" =========
" :shell 进入终端
" jsbeauty \ff
set helplang=cn
" =========
" js、css压缩
" =========
"autocmd BufWriteCmd *.js :call CompileJS() "保存时自动压缩js
"默认 :Gcc 命令压缩js
"autocmd BufWriteCmd *.js :call CompressCss() "保存时自动压缩css
"默认 :Ycc 命令压缩css