-
Notifications
You must be signed in to change notification settings - Fork 42
/
_vimrc
553 lines (481 loc) · 16.2 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
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
" Author: Asins - asinsimple AT gmail DOT com
" Get latest vimrc from http://nootn.com/
set nocompatible " be iMproved
filetype off " required!
" 设置leader为,
let mapleader=","
let maplocalleader=","
" 删除原有自动命令,防止.vimrc执行多次时自动命令出现多次
autocmd!
"编辑vim配置文件
if has("unix")
set fileformats=unix,mac,dos
let $VIMFILES = $HOME."/.vim"
else
set fileformats=dos,unix,mac
let $VIMFILES = $VIM."/vimfiles"
endif
set rtp+=$VIMFILES/bundle/Vundle.vim
call vundle#begin($VIMFILES.'/bundle')
" let Vundle manage Vundle
" required!
Plugin 'gmarik/Vundle.vim'
" My Bundles here:
"Color
Plugin 'asins/vim-colors'
Plugin 'scrooloose/nerdtree'
Plugin 'tpope/vim-fugitive'
Plugin 'bling/vim-airline'
Plugin 'kien/ctrlp.vim'
Plugin 'tacahiroy/ctrlp-funky'
Plugin 'jrhorn424/vim-multiple-cursors'
Plugin 'asins/vimcdoc'
Plugin 'asins/vim-dict'
Plugin 'Shougo/vimshell.vim'
Plugin 'scrooloose/nerdcommenter'
Plugin 'asins/renamer.vim'
Plugin 'auto_mkdir'
" Syntax
Plugin 'othree/html5.vim'
Plugin 'othree/html5-syntax.vim'
Plugin 'hallison/vim-markdown'
Plugin 'pangloss/vim-javascript'
Plugin 'nono/jquery.vim'
Plugin 'groenewege/vim-less'
" Indent
Plugin 'IndentAnything'
Plugin 'jiangmiao/simple-javascript-indenter'
Plugin 'Shougo/neocomplete.vim'
Plugin 'asins/mark'
" HTML tools
Plugin 'mattn/emmet-vim'
Plugin 'tpope/vim-ragtag'
Plugin 'matchit.zip' " 通过%跳转配对代码
Plugin 'MatchTag' " HTML标签高亮配对
Plugin 'maksimr/vim-jsbeautify' "HTML/CSS/JS代码格式化
call vundle#end()
filetype plugin indent on
" {{{ Win平台下窗口全屏组件 gvimfullscreen.dll
" Alt + Enter 全屏切换
" Shift + t 降低窗口透明度
" Shift + y 加大窗口透明度
" Shift + r 切换Vim是否总在最前面显示
" Vim启动的时候自动使用当前颜色的背景色以去除Vim的白色边框
if has('gui_running') && has('gui_win32') && has('libcall')
let g:MyVimLib = 'gvimfullscreen.dll'
function! ToggleFullScreen()
call libcall(g:MyVimLib, 'ToggleFullScreen', 1)
endfunction
let g:VimAlpha = 245
function! SetAlpha(alpha)
let g:VimAlpha = g:VimAlpha + a:alpha
if g:VimAlpha < 180
let g:VimAlpha = 180
endif
if g:VimAlpha > 255
let g:VimAlpha = 255
endif
call libcall(g:MyVimLib, 'SetAlpha', g:VimAlpha)
endfunction
let g:VimTopMost = 0
function! SwitchVimTopMostMode()
if g:VimTopMost == 0
let g:VimTopMost = 1
else
let g:VimTopMost = 0
endif
call libcall(g:MyVimLib, 'EnableTopMost', g:VimTopMost)
endfunction
"映射 Alt+Enter 切换全屏vim
noremap <a-enter> :call ToggleFullScreen()<cr>
"切换Vim是否在最前面显示
nmap <s-r> :call SwitchVimTopMostMode()<cr>
"增加Vim窗体的不透明度
nmap <s-t> :call SetAlpha(10)<cr>
"增加Vim窗体的透明度
nmap <s-y> :call SetAlpha(-10)<cr>
" 默认设置透明
autocmd GUIEnter * call libcallnr(g:MyVimLib, 'SetAlpha', g:VimAlpha)
endif
" }}}
" encode
set encoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936,cp950,latin1
" font
set linespace=0
language messages zh_CN.UTF-8
set vb t_vb= "关闭响铃和闪屏
set guioptions-=T "gui的工具栏
set guioptions-=r "gui的右边的滑动条
set guioptions-=L "gui的左边的滑动条
set guioptions-=m "gui的菜单
set showtabline=0 "Tab栏
set laststatus=2 " 默认显示状态栏
"set nocursorline
"set guifont=Monaco:h13
set guifont=YaHei\ Mono:h12
"set guifont=Consolas:h14
" 显示状态栏 (默认值为 1, 无法显示状态栏)
"set laststatus=2
" 设置在状态行显示的信息
"set statusline=\ %<%F[%1*%M%*%n%R%H]%=\ %y\ %0(%{&fileformat}\ [%{(&fenc==\"\"?&enc:&fenc).(&bomb?\",BOM\":\"\")}]\ %c:%l/%L%)
syntax on " 自动语法高亮
set nobackup " Close backup
set nowritebackup
set autochdir " 自动切换当前目录为当前文件所在的目录
set ignorecase " 搜索时忽略大小写,但在有一个或以上大写字母时仍大小写敏感
set nowrapscan " 搜索到文件两端时不重新搜索
set incsearch " 实时搜索
set hlsearch " 搜索时高亮显示被找到的文本
set mouse=a " 允许在所有模式下使用鼠标
" Style
colorscheme molokai
set number " 显示行号
set hidden " 允许在有未保存的修改时切换缓冲区
set wildmenu " 开启命令行补全
set smartindent " 智能自动缩进
set scrolloff=3 " 上下可视行数
set nocursorline " 不突出显示当前行
set showmatch "显示括号配对情况
set shortmess=atl "启动时不显示 捐赠提示
set helplang=cn
" Display extra whitespace
set list listchars=tab:\|\ ,trail:.,extends:>,precedes:<
" Tab
set tabstop=4 " 设定 tab 长度为 4
set softtabstop=4 " 设置按BackSpace的时候可以一次删除掉4个空格
set shiftwidth=4 " 设定 << 和 >> 命令移动时的宽度为 4
set smarttab
set noexpandtab " 使用Tab而非空格
set backspace=indent,eol,start " 让退格键和 Delete 键支持删除回车符
if has("unix")
set transparency=4 " 设置透明度
endif
"set foldenable 开启代码折叠功能
" 可组合 {} () <> []使用
" zc 关闭当前打开的折叠
" zo 打开当前的折叠
" zm 关闭所有折叠
" zM 关闭所有折叠及其嵌套的折叠
" zr 打开所有折叠
" zR 打开所有折叠及其嵌套的折叠
" zd 删除当前折叠
" zE 删除所有折叠
" zj 移动至下一个折叠
" zk 移动至上一个折叠
" zn 禁用折叠
" zN 启用折叠
" 新建的文件,刚打开的文件不折叠
autocmd BufNewFile,BufRead * setlocal nofoldenable list
" Filetype
autocmd BufRead,BufNewFile *.json set filetype=json
" 保存时自动删除多余空格
fun! StripTrailingWhitespace()
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" do the business:
%s/
$\|\s\+$//e
" clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfun
autocmd BufWritePre * call StripTrailingWhitespace()
" ===== 插件配置 =====
" dict {{{
"<ctrl-x>_<ctrl-k> 打开提示
autocmd filetype javascript setlocal dictionary+=$VIMFILES/bundle/vim-dict/dict/javascript.dic
autocmd filetype javascript setlocal dictionary+=$VIMFILES/bundle/vim-dict/dict/node.dic
autocmd filetype css setlocal dictionary+=$VIMFILES/bundle/vim-dict/dict/css.dic
autocmd filetype php setlocal dictionary+=$VIMFILES/bundle/vim-dict/dict/php.dic
" }}}
" {{{ ragtag HTML/XML缩进
let g:html_indent_script1 = "zero"
let g:html_indent_style1 = "zero"
" }}}
" {{{ emmet HTML代码生成
" 常用命令可看:http://nootn.com/blog/Tool/23/
let g:user_emmet_settings = {
\ 'lang': "zh-cn"
\ }
" <c-y>m 合并多行
" }}}
" {{{ NERDtree 文件管理器
" 让Tree把自己给装饰得多姿多彩漂亮点
let NERDChristmasTree=1
" 控制当光标移动超过一定距离时,是否自动将焦点调整到屏中心
let NERDTreeAutoCenter=1
" 指定书签文件
let NERDTreeBookmarksFile=$VIMFILES.'\NERDTree_bookmarks'
" 指定鼠标模式(1.双击打开 2.单目录双文件 3.单击打开)
let NERDTreeMouseMode=2
" 是否默认显示书签列表
let NERDTreeShowBookmarks=1
" 是否默认显示文件
let NERDTreeShowFiles=1
" 是否默认显示行号
let NERDTreeShowLineNumbers=0
" 窗口位置('left' or 'right')
let NERDTreeWinPos='left'
" 窗口宽度
let NERDTreeWinSize=31
nnoremap <Leader>tt :NERDTree<CR>
"}}}
" {{{ The-NERD-Commenter 注释代码用的,以下映射已写在插件中
let NERDMenuMode = 0
" <Leader>ca 在可选的注释方式之间切换,比如C/C++ 的块注释/* */和行注释//
" <Leader>cc 注释当前行
" <Leader>cs 以”性感”的方式注释
" <Leader>cA 在当前行尾添加注释符,并进入Insert模式
" <Leader>cu 取消注释
" <Leader>cm 添加块注释
" }}}
" {{{ vim-jsbeautify need nodejs 优化html/js/js代码,并不是简单的缩进噢
let g:config_Beautifier = {
\ 'js' : {
\ 'indent_size' : 4,
\ 'indent_style' : 'tab',
\ },
\ 'css' : {
\ 'indent_size' : 4,
\ 'indent_style' : 'tab',
\ },
\ 'html' : {
\ 'indent_size' : 4,
\ 'indent_style' : 'tab',
\ }
\ }
autocmd FileType javascript noremap <silent> <Leader>js :call JsBeautify()<cr>
autocmd FileType html noremap <silent> <Leader>js :call HtmlBeautify()<cr>
autocmd FileType css,less noremap <silent> <Leader>js :call CSSBeautify()<cr>
" }}}
" {{{ matchit.zip 对%命令进行扩展使得能在嵌套标签和语句之间跳转
" % 正向匹配 g% 反向匹配
" [% 定位块首 ]% 定位块尾
"}}}
" {{{ MatchTag HTML标签高亮配对
" }}}
" {{{ asins/renamer.vim 文件重命名
" :Renamer 将当前文件所在文件夹下的内容显示在一个新窗口
" :Ren 开始重命名
"}}}
" {{{ Mark 给各种tags标记不同的颜色,便于观看调式的插件。
" 在运行source后Mark会被覆盖
hi MarkWord1 ctermbg=Cyan ctermfg=Black guibg=#8CCBEA guifg=Black
hi MarkWord2 ctermbg=Green ctermfg=Black guibg=#A4E57E guifg=Black
hi MarkWord3 ctermbg=Yellow ctermfg=Black guibg=#FFDB72 guifg=Black
hi MarkWord4 ctermbg=Red ctermfg=Black guibg=#FF7272 guifg=Black
hi MarkWord5 ctermbg=Magenta ctermfg=Black guibg=#FFB3FF guifg=Black
hi MarkWord6 ctermbg=Blue ctermfg=Black guibg=#9999FF guifg=Black
nmap <silent> <Leader>hl <plug>MarkSet
vmap <silent> <Leader>hl <plug>MarkSet
nmap <silent> <Leader>hh <plug>MarkClear
nmap <silent> <Leader>hr <plug>MarkRegex
vmap <silent> <Leader>hr <plug>MarkRegex
" }}}
" vim-airline {{{
nmap <silent> <Leader>r :AirlineRefresh<CR>
let g:airline_theme='badwolf'
let g:airline_powerline_fonts=0
let g:airline_left_sep=''
let g:airline_right_sep=''
let g:airline_mode_map = {
\ '__' : '-',
\ 'n' : 'N',
\ 'i' : 'I',
\ 'R' : 'R',
\ 'c' : 'C',
\ 'v' : 'V',
\ 'V' : 'V',
\ '' : 'V',
\ 's' : 'S',
\ 'S' : 'S',
\ '' : 'S',
\ }
let g:airline#extensions#default#layout = [
\ [ 'a', 'b', 'c' ],
\ [ 'x', 'y', 'z']
\ ]
let g:airline_section_c = '%<%n %F'
let g:airline_section_x = '%{strlen(&ft) ? &ft : "Noft"}%{&bomb ? " BOM" : ""}'
let g:airline_section_y = '%{&fileformat} %{(&fenc == "" ? &enc : &fenc)}'
let g:airline_section_z = '%2l:%-1v/%L'
" }}}
" {{{ Code Completins
let g:acp_enableAtStartup = 0
let g:neocomplete#enable_at_startup = 1
" Use smartcase.
let g:neocomplete#enable_smart_case = 1
" <TAB>: completion.
inoremap <expr><TAB> pumvisible() ? '<C-n>' : '<TAB>'
" }}}
" ctrlp.vim {{{
let g:ctrlp_working_path_mode = 'ra'
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/]\.(git|hg|svn|cache|Trash)',
\ 'file': '\v\.(log|jpg|png|jpeg|exe|so|dll|pyc|pyo|swf|swp|psd|db)$'
\ }
" funky extension - jump to funciton defs
let g:ctrlp_extensions = ['funky']
let g:ctrlp_funky_syntax_highlight = 1
nnoremap <Leader>g :CtrlPFunky<Cr>
" narrow the list down with a word under cursor
nnoremap <Leader>G :execute 'CtrlPFunky ' . expand('<cword>')<Cr>
" Enable omni completion.
autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
nnoremap <silent> <Leader>f :CtrlPMRU<CR>
nnoremap <silent> <Leader>b :CtrlPBuffer<CR>
nnoremap <C-P> :CtrlP<Space>
" }}}
" {{{ vim-multiple-cursors 光标选择功能
"let g:multi_cursor_next_key='<C-n>'
"let g:multi_cursor_prev_key='<C-p>'
"let g:multi_cursor_skip_key='<C-x>'
"let g:multi_cursor_quit_key='<Esc>'
" }}}
" ===== 键盘映射 =====
" 快速编辑.vimrc文件
nmap <Leader>e :tabedit $MYVIMRC<CR>
" 自动运用设置
autocmd BufWritePost .vimrc,.gvimrc,_vimrc silent source %
" 窗口切换
nnoremap <c-h> <c-w>h
nnoremap <c-l> <c-w>l
nnoremap <c-j> <c-w>j
nnoremap <c-k> <c-w>k
" Buffers/Tab操作快捷方式!
nnoremap <s-h> :bprevious<cr>
nnoremap <s-l> :bnext<cr>
nnoremap <s-j> :tabnext<cr>
nnoremap <s-k> :tabprev<cr>
"nnoremap F :tabe %
" 插入模式下上下左右移动光标
inoremap <c-h> <left>
inoremap <c-l> <right>
inoremap <c-j> <c-o>gj
inoremap <c-k> <c-o>gk
"一些不错的映射转换语法(如果在一个文件中混合了不同语言时有用)
nnoremap <Leader>1 :set filetype=xhtml<cr>
nnoremap <Leader>2 :set filetype=css<cr>
nnoremap <Leader>3 :set filetype=javascript<cr>
nnoremap <Leader>4 :set filetype=php<cr>
" 代码垂直移动
nmap <s-down> mz:m+<cr>`z
nmap <s-up> mz:m-2<cr>`z
vmap <s-down> :m'>+<cr>`<my`>mzgv`yo`z
vmap <s-up> :m'<-2<cr>`>my`<mzgv`yo`z
" 全文搜索选中的文字
vnoremap <silent> <Leader>f y/<c-r>=escape(@", "\\/.*$^~[]")<cr><cr>
vnoremap <silent> <Leader>F y?<c-r>=escape(@", "\\/.*$^~[]")<cr><cr>
" 普通模式下 Shift+W 切换自动换行
nnoremap <s-w> :exe &wrap==1 ? 'set nowrap' : 'set wrap'<cr>
" 普通模式下 Ctrl+c 复制文件路径
nnoremap <c-c> :let @* = expand('%:p')<cr>
" 在VimScript中快速查找帮助文档
autocmd Filetype vim noremap <buffer> <F1> <Esc>:help <C-r><C-w><CR>
" ===== 工作环境配制 =====
" {{{ TUDOU 打开项目中的文件
function! GetOsPortUrl(url) " 格式化地址分隔线
if has("unix") || has('mac')
let extra = ':p:gs?\\?/?'
else
let extra = ':p:gs?/?\\?'
end
return fnamemodify(a:url, extra)
endfunction
" 获取项目目录
function! GetProjectPath(path, filename)
let path = fnamemodify(a:path, ':p:h')
let path = findfile(a:filename, '.;')
if(path == '')
echo 'Not find project directory.'
endif
return fnamemodify(path, ':h')
endfunction
" 打开@import 'xx/oo.less' 'xxx/oo'(less形式) 'xx/oo.css'
function! GetLessImportFile()
let prefpath = GetProjectPath('%', 'tpm-config.js').'\src\css\'
let filePath = substitute(getline('.'), '@import\s\+"\([^"]\+\)";\?', '\1', '')
if strridx(filePath, './') == 0 " 相对引入
let fullPath = expand('%:p:h') . substitute(filePath, '^\.', '', '')
else " 绝对引入
let fullPath = prefpath . filePath
endif
let fullPath = GetOsPortUrl(fullPath)
let fullPath = substitute(fullPath, '\/$', '', '')
if fnamemodify(fullPath, ':e') == ''
let fullPath = fullPath . '.less'
endif
execute ":e " fullPath
if findfile(fullPath) == ""
echo 'File not exist, Create now: '. fullPath
endif
endfunction
" 打开Require 引入的JS文件 './xxx' 'model/xxx' 'ooo/xxx.js' '../model/xxx'
function! GetRequireFile()
let prefpath = GetProjectPath('%', 'tpm-config.js').'\src\js\'
let filePath = GetFilePath()
if strridx(filePath, './') != -1 " 相对引入
let fullPath = expand('%:p:h') . '/' . filePath
else " 绝对引入
let fullPath = prefpath . filePath
endif
let fullPath = GetOsPortUrl(fullPath)
let fullPath = substitute(fullPath, '\/$', '', '')
if fnamemodify(fullPath, ':e') == ''
let fullPath = fullPath . '.js'
endif
execute ":e " fullPath
if findfile(fullPath) == ""
echo 'File not exist, Create now: '. fullPath
endif
endfunction
function! GetFilePath()
let line = substitute(expand('<cWORD>'), "'", '"', "g")
let mlist = matchlist(line, '.*\"\(.\+\)\".*')
if len(mlist) > 0
return mlist[1]
else
let line = substitute(getline('.'), "'", '"', "g")
let mlist = matchlist(line, '.*\"\(.\+\)\".*')
if len(mlist) > 0
return mlist[1]
endif
endif
return ''
endfunction
function! OpenRequireFile()
if strridx(getline('.'), '@import') >= 0
call GetLessImportFile()
else
call GetRequireFile()
endif
endfunction
nmap <silent> <Leader>gf :call OpenRequireFile()<cr>
function! YtpmVM(filePath, env)
let s:cmt = '!ytpm vm "'.a:filePath.'" '.a:env.' --config="'.$HOME.'/tudou/Static/v3/tpm-config.js"'
"echo s:cmt
exe s:cmt
endfunction
autocmd BufRead,BufNewFile *.vm setlocal ft=vm syntax=html
autocmd filetype vm noremap <Leader>ywt :call YtpmVM('%', 'wwwtest')<cr>
autocmd filetype vm noremap <Leader>ywt1 :call YtpmVM('%', 'wwwtest1')<cr>
autocmd filetype vm noremap <Leader>ywt2 :call YtpmVM('%', 'wwwtest2')<cr>
autocmd filetype vm noremap <Leader>ybt :call YtpmVM('%', 'beta')<cr>
autocmd filetype vm noremap <Leader>ybt1 :call YtpmVM('%', 'beta1')<cr>
autocmd filetype vm noremap <Leader>ybt2 :call YtpmVM('%', 'beta2')<cr>
" }}}
" need npm install less -g
function! LessToCss()
let current_file = shellescape(expand('%:p'))
let filename = shellescape(expand('%:r'))
let command = "silent !lessc " . current_file . " " . filename . ".css"
execute command
endfunction
autocmd BufWritePost,FileWritePost *.less call LessToCss()