我的VIM配置
1 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 2 "" 使用办法 3 "" 1: git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle 4 "" 2: vim foo 5 "" 3: :BundleUpdate 6 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 7 "" 1: gui全屏的时候会有一点小问题 8 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 9 "" Date: 2014年 03月 17日 星期一 09:35:03 CST 10 "" Date: 2014 07 24 11 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 12 13 "设置<leader>为逗号比较好,因为不同的键盘\按键会有不一样的位置 14 let mapleader=',' 15 16 " 快速打开vimrc的配置文件 17 map <silent> <leader>ee :tabnew $HOME/.vimrc<cr> 18 19 " ^Z快速进入shell 20 nmap <c-z> :shell<cr> 21 22 " 判断操作系统 23 if (has("win32") || has("win64") || has("win32unix")) 24 let g:isWin = 1 25 else 26 let g:isWin = 0 27 endif 28 29 " 判断是终端还是gvim 30 if has("gui_running") 31 let g:isGUI = 1 32 else 33 let g:isGUI = 0 34 endif 35 36 "设置行号 37 :set nu 38 "自动缩进 39 :set autoindent 40 41 "设置缩进为4个字符,默认为8个 42 set softtabstop=4 43 set shiftwidth=4 44 set smarttab 45 set expandtab 46 47 "增加自动补齐路径 48 set path=.,/usr/include,/usr/include/c++/4.4.4 49 "打开语法高亮 50 syntax on 51 syntax enable 52 "设置背景颜色 53 set background=dark 54 "深色主题 对保护视力有一定的帮助 55 colorscheme delek 56 colorscheme evening 57 " 设置注释为绿色 58 highlight Comment ctermfg=red guifg=green 59 " 设置自动补齐窗口配色 60 highlight Pmenu guibg=lightgrey ctermbg=lightgrey guifg=black ctermfg=black 61 highlight PmenuSel guibg=lightgrey ctermbg=blue guifg=blue ctermfg=red 62 63 " 右下角显示完整命令 64 set showcmd 65 66 " 打开智能识别 67 " 自动识别文件类型 68 " 用文件类型plugin脚本 69 " 使用缩进定义文件 70 filetype plugin indent on 71 "help new-omni-completion help compl-omni "help ft-c-omni 72 "有一点要注意一下, 切记, 关於omni的设定要写在 filetype plugin ... on, 的后面 73 "autocmd FileType * set omnifunc=syntaxcomplete#Complete 74 autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete 75 autocmd FileType python set omnifunc=pythoncomplete#Complete 76 autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS 77 autocmd FileType html set omnifunc=htmlcomplete#CompleteTags 78 autocmd FileType css set omnifunc=csscomplete#CompleteCSS 79 autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags 80 autocmd FileType java set omnifunc=javacomplete#Complete 81 82 "查看制表符 83 set list 84 set listchars=tab:>-,trail:- 85 86 "设置屏幕上下边界 87 set scrolloff=5 88 "set nowrap "用zl zh 移动 89 "set wrap "用gj gk 移动 90 91 " 让左右箭头可以智能的上下左右 92 set whichwrap=b,s,<,>,h,l 93 94 " ctags 索引文件 95 set tags+=/usr/include/tags 96 set tags+=/usr/include/c++/4.4.4/tags 97 " 增加自动补齐路径 98 set path=.,/usr/include,/usr/include/c++/4.4.4 99 100 set cindent "C/C++风格缩进 101 102 set shortmess=atI "去掉欢迎界面 103 set ignorecase "搜索时忽略大小写 104 set showmatch "显示匹配的括号 105 set lbr "在breakat字符处而不是最后一个字符处断行 106 set history=400 "vim记住的历史操作的数量,默认的是20 107 set autoread "当文件在外部被修改时,自动重新读取 108 set mouse=n "在所有模式下都允许使用鼠标,还可以是n,v,i,c等 109 110 "在gvim中高亮当前行 111 if (g:isGUI) 112 set cursorline 113 colorscheme wombat 114 hi cursorline guibg=#333333 115 hi CursorColumn guibg=#333333 116 "set guifont=Consolas\ 10 117 "set guifontwide=Consolas\ 10 118 set guifont=DejaVu\ Sans\ Mono\ 10 119 set gfw=DejaVu\ Sans\ Mono\ 10 120 " 不显示toolbar 121 set guioptions-=T 122 " 不显示菜单栏 123 "set guioptions-=m 124 endif 125 126 " 设置字符集编码,默认使用utf8 127 if (g:isWin) 128 let &termencoding=&encoding " 通常win下的encoding为cp936 129 set fileencodings=utf8,cp936,ucs-bom,latin1 130 else 131 set encoding=utf8 132 set fileencodings=utf8,gb2312,gb18030,ucs-bom,latin1 133 endif 134 135 " 状态栏 136 set laststatus=2 " 总是显示状态栏 137 highlight StatusLine cterm=bold ctermfg=yellow ctermbg=blue 138 " 获取当前路径,将$HOME转化为~ 139 function! CurDir() 140 let curdir = substitute(getcwd(), $HOME, "~", "g") 141 return curdir 142 endfunction 143 set statusline=[%n]\ %f%m%r%h\ \|\ \ pwd:\ %{CurDir()}\ \ \|%=\|\ %l,%c\ %p%%\ \|\ asci 144 145 " 第80列往后加下划线 146 "au BufWinEnter * let w:m2=matchadd('Underlined', '\%>' . 80 . 'v.\+', -1) 147 148 " 根据给定方向搜索当前光标下的单词,结合下面两个绑定使用 149 function! VisualSearch(direction) range 150 let l:saved_reg = @" 151 execute "normal! vgvy" 152 let l:pattern = escape(@", '\\/.*$^~[]') 153 let l:pattern = substitute(l:pattern, "\n$", "", "") 154 if a:direction == 'b' 155 execute "normal ?" . l:pattern . "<cr>" 156 else 157 execute "normal /" . l:pattern . "<cr>" 158 endif 159 let @/ = l:pattern 160 let @" = l:saved_reg 161 endfunction 162 "用 */# 向 前/后 搜索光标下的单词 163 vnoremap <silent> * :call VisualSearch('f')<CR> 164 vnoremap <silent> # :call VisualSearch('b')<CR> 165 166 " 在文件名上按时,在新的tab中打开 167 " map gf :tabnew <cfile><cr> 168 169 " 恢复上次文件打开位置 170 set viminfo='10,\"100,:20,%,n~/.viminfo 171 au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif 172 173 "从系统剪切板中复制,剪切,粘贴 174 "map <F7> "+y 175 "map <F8> "+x 176 "map <F9> "+p 177 178 " 快捷输入 179 " 自动完成括号和引号 180 inoremap <leader>1 ()<esc>:let leavechar=")"<cr>i 181 inoremap {{ {<cr>}<esc>kA<cr> 182 183 184 185 "使用caps Lock代替ESC,如果是输入大量的大写时,可以先输入小写,然后选中用U改变 186 "在终端中输入 187 "xmodmap -e 'clear Lock' -e 'keycode 0x42 = Escape' 188 189 "快速编译选项 190 "map<F5> :w<Enter> :!make<Enter> 191 "<F2>快速打开当前目录下的文件 <c-f2>快速打开指定目录下的文件 192 map <F2> :Texplore<cr> 193 map <F3> :tabpre<cr> 194 map <F4> :tabnext<cr> 195 map <F5> <esc>:w<cr><esc>:make<cr>:cw<cr><c-w>j 196 "map <F5> <esc>:w<cr><esc>:!make<cr>:cw<cr><c-w>j 197 map <cr> <cr>:cclose<cr> 198 map<F6> :!make run<Enter> 199 "map<F6> : !clear && ./%< <Enter> 200 201 nnoremap <space> @=((foldclosed(line('.'))<0)? 'zc':'zo') <cr> 202 set foldmethod=indent 203 set foldmethod=syntax 204 set nofoldenable 205 inoremap <F12> <esc>:call FoldEnable()<cr> 206 map <silent> <F12> :call FoldEnable()<cr> 207 208 let g:s_foldenable=0 209 function! FoldEnable() 210 if exists("g:s_foldenable") 211 unlet g:s_foldenable 212 set nofoldenable 213 else 214 let g:s_foldenable=1 215 set foldenable 216 endif 217 endfunction 218 219 "设置行高亮 220 set cursorline 221 "hi cursorline guibg=Grey40 guifg=red term=BOLD 222 223 "窗口之间的快速跳转 224 noremap <c-h> <c-w>h 225 noremap <c-j> <c-w>j 226 noremap <c-k> <c-w>k 227 noremap <c-l> <c-w>l 228 229 " 更新ctags和cscope索引 230 " href: http://www.vimer.cn/2009/10/把vim打造成一个真正的ide2.html 231 " 稍作修改,提取出DeleteFile函数,修改ctags和cscope执行命令 232 map <F7> :call Do_CsTag()<cr> 233 function! Do_CsTag() 234 let dir = getcwd() 235 "先删除已有的tags和cscope文件,如果存在且无法删除,则报错。 236 if ( DeleteFile(dir, "tags") ) 237 return 238 endif 239 if ( DeleteFile(dir, "cscope.files") ) 240 return 241 endif 242 if ( DeleteFile(dir, "cscope.out") ) 243 return 244 endif 245 246 if(executable('ctags')) 247 silent! execute "!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q ." 248 endif 249 if(executable('cscope') && has("cscope")) 250 if(g:isWin) 251 silent! execute "!dir /s/b *.c,*.cpp,*.h,*.java,*.cs >> cscope.files" 252 else 253 silent! execute "!find . -iname '*.[ch]' -o -name '*.cpp' > cscope.files" 254 endif 255 silent! execute "!cscope -b" 256 execute "normal :" 257 if filereadable("cscope.out") 258 execute "cs add cscope.out" 259 endif 260 endif 261 " 刷新屏幕 262 execute "redr!" 263 endfunction 264 265 function! DeleteFile(dir, filename) 266 if filereadable(a:filename) 267 if (g:isWin) 268 let ret = delete(a:dir."\\".a:filename) 269 else 270 let ret = delete("./".a:filename) 271 endif 272 if (ret != 0) 273 echohl WarningMsg | echo "Failed to delete ".a:filename | echohl None 274 return 1 275 else 276 return 0 277 endif 278 endif 279 return 0 280 endfunction 281 282 " cscope 绑定 283 if has("cscope") 284 set csto=1 285 set cst 286 set nocsverb 287 if filereadable("cscope.out") 288 cs add cscope.out 289 endif 290 set csverb 291 " s: C语言符号 g: 定义 d: 这个函数调用的函数 c: 调用这个函数的函数 292 " t: 文本 e: egrep模式 f: 文件 i: include本文件的文件 293 nmap <leader>ss :cs find s <C-R>=expand("<cword>")<CR><CR> 294 nmap <leader>sg :cs find g <C-R>=expand("<cword>")<CR><CR> 295 nmap <leader>sc :cs find c <C-R>=expand("<cword>")<CR><CR> 296 nmap <leader>st :cs find t <C-R>=expand("<cword>")<CR><CR> 297 nmap <leader>se :cs find e <C-R>=expand("<cword>")<CR><CR> 298 nmap <leader>sf :cs find f <C-R>=expand("<cfile>")<CR><CR> 299 nmap <leader>si :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR> 300 nmap <leader>sd :cs find d <C-R>=expand("<cword>")<CR><CR> 301 endif 302 303 304 305 " 插件窗口的宽度,如TagList,NERD_tree等,自己设置 306 let s:PlugWinSize = 20 307 308 "下面是Vundle插件 309 set rtp+=~/.vim/bundle/vundle 310 call vundle#rc() 311 312 "============================================================ 313 "vim分屏执行shell 314 "使用的命令是 ConqueTermSplit <command> , ConqueTermVSplit <command> 315 Bundle 'vim-scripts/Conque-Shell' 316 317 318 "============================================================ 319 "对不同的filetype进行注释 320 "使用的方法是 gc{motion} , {visual}gc , gcu 撤销 321 " \\{motion} , {visual}\\ 322 Bundle 'tpope/vim-commentary' 323 324 325 "============================================================ 326 "类似vc中的workspace,列出文件中的所有宏,所有全局变量,函数名 327 Bundle 'taglist.vim' 328 "下面是配置 329 let Tlist_Ctags_Cmd='/usr/bin/ctags -R' 330 let Tlist_OnlyWindow=1 331 let Tlist_Sort_Type='name' 332 let Tlist_Auto_Open=1 333 let Tlist_WinHeight=10 334 "let Tlist_WinWidth=10 335 let Tlist_Use_Horiz_Window=0 336 let Tlist_Exit_OnlyWindow=1 337 "使用TlistToggle命令打开 338 339 340 "============================================================ 341 "Winanager 管理各个窗口 342 "Bundle 'winmanager' 343 ""下面是配置 344 "let g:persistentBehaviour=0 "只剩下一个窗口时退出 345 "let g:winManagerWidth=20 346 "let g:defaultExplorer=1 347 "let g:winManagerWindowLayout='FileExplorer,Taglist|BufExplorer' 348 "使用WMToggle命令打开 349 350 "============================================================ 351 "BufExplorer 352 "Bundle 'bufexplorer.zip' 353 354 "============================================================ 355 "NERD_tree 显示一棵目录树 与默认的FileExplorer类似 356 "Bundle 'scrooloose/nerdtree' 357 "下面是配置 358 "let g:NERDTree_title="[目录树]" 359 "使用NERDTreeToggle命令打开 360 361 362 "============================================================ 363 "OmniCppComplete 自动补全加智能感应 364 "进入要补全的源代码目录执行 ctags -R --c++-kinds=+p 365 " --fields=+iaS 366 " --extra=+q 367 " 选项太多的话,会卡顿 368 "下面是配置 369 "Bundle 'OmniCppComplete' 370 "set tags+=~ 371 "let OmniCpp_NamespaceSearch=1 372 "let OmniCpp_GlobalScopeSearch=1 373 "let OmniCpp_ShowAccess=1 374 "let OmniCpp_ShowPrototypeInAbbr=1 "显示参数列表 375 "let OmniCpp_MayCompleteDot=1 "输入.自动补全 376 "let OmniCpp_MayCompleteArrow=1 "输入->自动补全 377 "let OmniCpp_MayCompleteScope=1 "输入::自动补全 378 "let OmniCpp_DefaultNamespaces=["std","_GLIBCXX_STD"] 379 "set completeopt=menu,longest 380 "au CursorMovedI,InsertLeave * if pumvisible()==0 | silent!pclose | endif 381 "弹出下拉类别的颜色 382 "hi Pmenu ctermbg=2 ... 383 "hi PmenuSel ctermbg=5 ... 384 385 386 "============================================================ 387 "SuperTab 加速补全 388 "Bundle 'SuperTab' 389 "就两个参数 390 "let g:SuperTabRetainCompletionType=2 391 "let g:SuperTabDefaultCompletionType="<c-x><c-o>" 392 "imap <tab> <c-x><c-o> 393 394 395 "============================================================ 396 "Visual-Mark 高亮书签 397 "Bundle 'vim-scripts/Visual-Mark' 398 "使用 mm 高亮 399 400 401 "============================================================ 402 "Mark,vim 对选中的单词进行高亮 403 Bundle 'vim-scripts/Mark--Karkat' 404 "let mapleader="\" 405 "用法 406 "<leader>m 标记/取消 <leader> 407 "<leader>n 关闭 <leader>r 正值表达式标记 408 "<leader>* 同组标记的下一个 <leader># 同组标记的上一个 409 "<leader>/ 全部标记的下一个 <leader>? 全部标记的上一个 410 "高亮颜色 411 "hi MarkWord1 ctermbg=... 412 "hi MarkWord. 413 "hi MarkWord6 ctermbg=... 414 415 416 "============================================================ 417 "vim-multiple-cursors 多光标选择 418 "该插件有bug 419 "Bundle 'vim-multiple-cursors' 420 "let g:multi_cursor_next_key='<c-n>' 421 "let g:multi_cursor_prev_key='<c-p>' 422 "let g:multi_cursor_skip_key='<c-x>' 423 "let g:multi_cursor_quit_key='<esc>' 424 "用法 425 "使用c-n选择 c,s 两个字母来替换 i,a 两个用来修改 426 "用Visul 模式下选择多行然后进行正值表达式匹配 427 " :'<,'> MultipleCursorsFind 428 429 430 "============================================================ 431 "vim-airline 修改状态条的颜色等信息 其实 432 Bundle 'bling/vim-airline' 433 "let g:airline_left_sep = '»' 434 let g:airline_left_sep = '▶' 435 let g:airline_left_alt_sep = '>' 436 "let g:airline_right_sep = '«' 437 let g:airline_right_sep = '◀' 438 let g:airline_right_alt_sep = '<' 439 "let g:airline_symbols.linenr = '␊' 440 "let g:airline_symbols.linenr = '' 441 "let g:airline_symbols.linenr = '¶' 442 "let g:airline_symbols.branch = '⎇' 443 "let g:airline_symbols.paste = 'ρ' 444 "let g:airline_symbols.paste = 'Þ' 445 "let g:airline_symbols.paste = '∥' 446 "let g:airline_symbols.whitespace = 'Ξ' 447 let g:airline_section_a=airline#section#create(['mode']) 448 let g:airline_section_b=airline#section#create(['hunks']) 449 let g:airline_section_c=airline#section#create(['%{getcwd()}','%f']) 450 let g:airline_section_x=airline#section#create(['branch','ffenc']) 451 let g:airline_section_y=airline#section#create(['','[TYPE:','filetype',']','[TIME:','%{strftime("%H:%M")}',']']) 452 "let g:airline_section_z=airline#section#create() 453 "let g:airline_section_a= 454 "let g:airline_section_b='%{getcwd()}' 455 "let g:airline_section_c= 456 "let g:airline_section_x=airline#section#create(['mode',' ','branch',' ','ffenc']) 457 " 458 "let g:airline_section_y='%{FileType}' 459 460 "let g:airline_section_y='%a' 461 "let g:airline_section_z='%{strftime("%H:%M")}' 462 "使用AirlineToggle打开 463 "AirlineTheme ... 来选择配色 464 465 466 "============================================================ 467 "EasyMotion 快速定位移动 468 Bundle 'EasyMotion' 469 "let g:EasyMotion_leader_key='<leader><leader>' 470 "用法 471 " <leader><leader>{motion} 472 " \\fo 表示向下查找所有o字母 473 let g:EasyMotion_keys='abcdefghijklmnopqrstuvwxyz' 474 let g:EasyMotion_do_shade=1 " 1表示背景有高亮 475 " hi EasyMotionTarget ctermbg=... 476 " hi EasyMotionShade ctermbg=... 477 " hi link EasyMotionShade Comment 478 479 480 "============================================================ 481 "css-color.vim 对css中颜色的值进行高亮,需要Gui 482 "Bundle 'css_color.vim' 483 484 485 "============================================================ 486 "AutoComplPop Acp自动弹出 487 "Bundle 'AutoComplPop' 488 "let g:acp_enableAtStartup=0 489 "下面这个是设置只是对前端起作用,因为对其他支持不是很好 490 "autocmd FileType html,css,htm,xml,jsp,php exec "AutoComplPopEnable" 491 492 493 "============================================================ 494 "Javascript.vim 对js代码高亮 495 "Bundle 'javascript.vim' 496 "setlocal foldlevel=3 "折叠的层数 497 "let b:javascript_fold=1 498 "let javascript_enable_domhtmlcss=1 "对dom,html,css支持 499 500 501 "============================================================ 502 "Emmet 插件 标签框架自动生成 503 "Bundle 'mattn/emmet-vim' 504 "let g:user_emmet_mode='niv' "表示insert,normal,visual模式 505 "let g:user_emmet_install_global=0 506 "autocmd FileType html,css,jsp,php,htm EmmetInstall "只对网页启用 507 "let g:user_emmet_leader_key='<c-y>' "默认是<c-y> 508 "使用的方法 509 " ul>li*4 然后 <c-y>, 510 511 512 "============================================================
作者:无脑仔的小明 出处:http://www.cnblogs.com/wunaozai/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 如果文中有什么错误,欢迎指出。以免更多的人被误导。有需要沟通的,可以站内私信,文章留言,或者关注“无脑仔的小明”公众号私信我。一定尽力回答。 |