1.安装vundle管理插件
sudo apt-get install vimsudo apt-get install gvimsudo apt-get install gitmkdir .vimcd .vimmkdir bundlecd bundlegit clone https://github.com/gmarik/vundle.git
2.gvim配置文件
1 " ============================================================================= 2 " << 判断操作系统是 Windows 还是 Linux 和判断是终端还是 Gvim >> 3 " ============================================================================= 4 5 " ----------------------------------------------------------------------------- 6 " < 判断操作系统是否是 Windows 还是 Linux > 7 " ----------------------------------------------------------------------------- 8 let g:iswindows = 0 9 let g:islinux = 0 10 if(has("win32") || has("win64") || has("win95") || has("win16")) 11 let g:iswindows = 1 12 else 13 let g:islinux = 1 14 endif 15 16 " ----------------------------------------------------------------------------- 17 " < 判断是终端还是 Gvim > 18 " ----------------------------------------------------------------------------- 19 if has("gui_running") 20 let g:isGUI = 1 21 else 22 let g:isGUI = 0 23 endif 24 25 26 " ============================================================================= 27 " << 以下为软件默认配置 >> 28 " ============================================================================= 29 30 " ----------------------------------------------------------------------------- 31 " < Windows Gvim 默认配置> 做了一点修改 32 " ----------------------------------------------------------------------------- 33 if (g:iswindows && g:isGUI) 34 source $VIMRUNTIME/vimrc_example.vim 35 source $VIMRUNTIME/mswin.vim 36 behave mswin 37 set diffexpr=MyDiff() 38 39 function MyDiff() 40 let opt = '-a --binary ' 41 if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif 42 if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif 43 let arg1 = v:fname_in 44 if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif 45 let arg2 = v:fname_new 46 if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif 47 let arg3 = v:fname_out 48 if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif 49 let eq = '' 50 if $VIMRUNTIME =~ ' ' 51 if &sh =~ '\' . arg3 . eq 61 endfunction 62 endif 63 64 " ----------------------------------------------------------------------------- 65 " < Linux Gvim/Vim 默认配置> 做了一点修改 66 " ----------------------------------------------------------------------------- 67 if g:islinux 68 set hlsearch "高亮搜索 69 set incsearch "在输入要搜索的文字时,实时匹配 70 71 " Uncomment the following to have Vim jump to the last position when 72 " reopening a file 73 if has("autocmd") 74 au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif 75 endif 76 77 if g:isGUI 78 " Source a global configuration file if available 79 if filereadable("/etc/vim/gvimrc.local") 80 source /etc/vim/gvimrc.local 81 endif 82 else 83 " This line should not be removed as it ensures that various options are 84 " properly set to work with the Vim-related packages available in Debian. 85 runtime! debian.vim 86 87 " Vim5 and later versions support syntax highlighting. Uncommenting the next 88 " line enables syntax highlighting by default. 89 if has("syntax") 90 syntax on 91 endif 92 93 set mouse=a " 在任何模式下启用鼠标 94 set t_Co=256 " 在终端启用256色 95 set backspace=2 " 设置退格键可用 96 97 " Source a global configuration file if available 98 if filereadable("/etc/vim/vimrc.local") 99 source /etc/vim/vimrc.local100 endif101 endif102 endif103 104 105 " =============================================================================106 " << 以下为用户自定义配置 >>107 " =============================================================================108 109 " -----------------------------------------------------------------------------110 " < Vundle 插件管理工具配置 >111 " -----------------------------------------------------------------------------112 " 用于更方便的管理vim插件,具体用法参考 :h vundle 帮助113 " Vundle工具安装方法为在终端输入如下命令114 " git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle115 " 如果想在 windows 安装就必需先安装 "git for window",可查阅网上资料116 117 set nocompatible "禁用 Vi 兼容模式118 filetype off "禁用文件类型侦测119 120 if g:islinux121 set rtp+=~/.vim/bundle/vundle/122 call vundle#rc()123 else124 set rtp+=$VIM/vimfiles/bundle/vundle/125 call vundle#rc('$VIM/vimfiles/bundle/')126 endif127 128 " 使用Vundle来管理插件,这个必须要有。129 Bundle 'gmarik/vundle'130 131 " 以下为要安装或更新的插件,不同仓库都有(具体书写规范请参考帮助)132 Bundle 'a.vim'133 Bundle 'Align'134 Bundle 'jiangmiao/auto-pairs'135 Bundle 'bufexplorer.zip'136 Bundle 'ccvext.vim'137 Bundle 'cSyntaxAfter'138 Bundle 'ctrlpvim/ctrlp.vim'139 Bundle 'mattn/emmet-vim'140 Bundle 'Yggdroot/indentLine'141 Bundle 'vim-javacompleteex'142 Bundle 'Mark--Karkat'143 Bundle 'Shougo/neocomplcache.vim'144 Bundle 'scrooloose/nerdcommenter'145 Bundle 'scrooloose/nerdtree'146 Bundle 'OmniCppComplete'147 Bundle 'Lokaltog/vim-powerline'148 Bundle 'repeat.vim'149 Bundle 'msanders/snipmate.vim'150 Bundle 'wesleyche/SrcExpl'151 Bundle 'std_c.zip'152 Bundle 'tpope/vim-surround'153 Bundle 'scrooloose/syntastic'154 Bundle 'majutsushi/tagbar'155 Bundle 'taglist.vim'156 Bundle 'TxtBrowser'157 Bundle 'ZoomWin'158 159 " -----------------------------------------------------------------------------160 " < 编码配置 >161 " -----------------------------------------------------------------------------162 " 注:使用utf-8格式后,软件与程序源码、文件路径不能有中文,否则报错163 set encoding=utf-8 "设置gvim内部编码,默认不更改164 set fileencoding=utf-8 "设置当前文件编码,可以更改,如:gbk(同cp936)165 set fileencodings=ucs-bom,utf-8,gbk,cp936,latin-1 "设置支持打开的文件的编码166 167 " 文件格式,默认 ffs=dos,unix168 set fileformat=unix "设置新(当前)文件的 格式,可以更改,如:dos(windows系统常用)169 set fileformats=unix,dos,mac "给出文件的 格式类型170 171 if (g:iswindows && g:isGUI)172 "解决菜单乱码173 source $VIMRUNTIME/delmenu.vim174 source $VIMRUNTIME/menu.vim175 176 "解决consle输出乱码177 language messages zh_CN.utf-8178 endif179 180 " -----------------------------------------------------------------------------181 " < 编写文件时的配置 >182 " -----------------------------------------------------------------------------183 filetype on "启用文件类型侦测184 filetype plugin on "针对不同的文件类型加载对应的插件185 filetype plugin indent on "启用缩进186 set smartindent "启用智能对齐方式187 set expandtab "将Tab键转换为空格188 set tabstop=4 "设置Tab键的宽度,可以更改,如:宽度为2189 set shiftwidth=4 "换行时自动缩进宽度,可更改(宽度同tabstop)190 set smarttab "指定按一次backspace就删除shiftwidth宽度191 set foldenable "启用折叠192 set foldmethod=indent "indent 折叠方式193 " set foldmethod=marker "marker 折叠方式194 195 " 常规模式下用空格键来开关光标行所在折叠(注:zR 展开所有折叠,zM 关闭所有折叠)196 nnoremap @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo') 197 198 " 当文件在外部被修改,自动更新该文件199 set autoread200 201 " 常规模式下输入 cS 清除行尾空格202 nmap cS :%s/\s\+$//g :noh 203 204 " 常规模式下输入 cM 清除行尾 ^M 符号205 nmap cM :%s/\r$//g :noh 206 207 set ignorecase "搜索模式里忽略大小写208 set smartcase "如果搜索模式包含大写字符,不使用 'ignorecase' 选项,只有在输入搜索模式并且打开 'ignorecase' 选项时才会使用209 " set noincsearch "在输入要搜索的文字时,取消实时匹配210 211 " Ctrl + K 插入模式下光标向上移动212 imap 213 214 " Ctrl + J 插入模式下光标向下移动215 imap 216 217 " Ctrl + H 插入模式下光标向左移动218 imap 219 220 " Ctrl + L 插入模式下光标向右移动221 imap 222 223 " 启用每行超过80列的字符提示(字体变蓝并加下划线),不启用就注释掉224 au BufWinEnter * let w:m2=matchadd('Underlined', '\%>' . 80 . 'v.\+', -1)225 226 " -----------------------------------------------------------------------------227 " < 界面配置 >228 " -----------------------------------------------------------------------------229 set number "显示行号230 set laststatus=2 "启用状态栏信息231 set cmdheight=2 "设置命令行的高度为2,默认为1232 set cursorline "突出显示当前行233 " set guifont=YaHei_Consolas_Hybrid:h10 "设置字体:字号(字体名称空格用下划线代替)234 set nowrap "设置不自动换行235 set shortmess=atI "去掉欢迎界面236 237 " 设置 gVim 窗口初始位置及大小238 if g:isGUI239 " au GUIEnter * simalt ~x "窗口启动时自动最大化240 winpos 100 10 "指定窗口出现的位置,坐标原点在屏幕左上角241 set lines=38 columns=120 "指定窗口大小,lines为高度,columns为宽度242 endif243 244 " 设置代码配色方案245 if g:isGUI246 colorscheme elflord "Gvim配色方案247 else248 colorscheme elflord "终端配色方案249 endif250 251 " 显示/隐藏菜单栏、工具栏、滚动条,可用 Ctrl + F11 切换252 if g:isGUI253 set guioptions-=m254 set guioptions-=T255 set guioptions-=r256 set guioptions-=L257 nmap :if &guioptions =~# 'm' 258 \set guioptions-=m 259 \set guioptions-=T 260 \set guioptions-=r 261 \set guioptions-=L 262 \else 263 \set guioptions+=m 264 \set guioptions+=T 265 \set guioptions+=r 266 \set guioptions+=L 267 \endif 268 endif269 270 " -----------------------------------------------------------------------------271 " < 编译、连接、运行配置 (目前只配置了C、C++、Java语言)>272 " -----------------------------------------------------------------------------273 " F9 一键保存、编译、连接存并运行274 nmap :call Run() 275 imap :call Run() 276 277 " Ctrl + F9 一键保存并编译278 nmap :call Compile() 279 imap :call Compile() 280 281 " Ctrl + F10 一键保存并连接282 nmap :call Link() 283 imap :call Link() 284 285 let s:LastShellReturn_C = 0286 let s:LastShellReturn_L = 0287 let s:ShowWarning = 1288 let s:Obj_Extension = '.o'289 let s:Exe_Extension = '.exe'290 let s:Class_Extension = '.class'291 let s:Sou_Error = 0292 293 let s:windows_CFlags = 'gcc\ -fexec-charset=gbk\ -Wall\ -g\ -O0\ -c\ %\ -o\ %<.o'294 let s:linux_CFlags = 'gcc\ -Wall\ -g\ -O0\ -c\ %\ -o\ %<.o'295 296 let s:windows_CPPFlags = 'g++\ -fexec-charset=gbk\ -Wall\ -g\ -O0\ -c\ %\ -o\ %<.o'297 let s:linux_CPPFlags = 'g++\ -Wall\ -g\ -O0\ -c\ %\ -o\ %<.o'298 299 let s:JavaFlags = 'javac\ %'300 301 func! Compile()302 exe ":ccl"303 exe ":update"304 let s:Sou_Error = 0305 let s:LastShellReturn_C = 0306 let Sou = expand("%:p")307 let v:statusmsg = ''308 if expand("%:e") == "c" || expand("%:e") == "cpp" || expand("%:e") == "cxx"309 let Obj = expand("%:p:r").s:Obj_Extension310 let Obj_Name = expand("%:p:t:r").s:Obj_Extension311 if !filereadable(Obj) || (filereadable(Obj) && (getftime(Obj) < getftime(Sou)))312 redraw!313 if expand("%:e") == "c"314 if g:iswindows315 exe ":setlocal makeprg=".s:windows_CFlags316 else317 exe ":setlocal makeprg=".s:linux_CFlags318 endif319 echohl WarningMsg | echo " compiling..."320 silent make321 elseif expand("%:e") == "cpp" || expand("%:e") == "cxx"322 if g:iswindows323 exe ":setlocal makeprg=".s:windows_CPPFlags324 else325 exe ":setlocal makeprg=".s:linux_CPPFlags326 endif327 echohl WarningMsg | echo " compiling..."328 silent make329 endif330 redraw!331 if v:shell_error != 0332 let s:LastShellReturn_C = v:shell_error333 endif334 if g:iswindows335 if s:LastShellReturn_C != 0336 exe ":bo cope"337 echohl WarningMsg | echo " compilation failed"338 else339 if s:ShowWarning340 exe ":bo cw"341 endif342 echohl WarningMsg | echo " compilation successful"343 endif344 else345 if empty(v:statusmsg)346 echohl WarningMsg | echo " compilation successful"347 else348 exe ":bo cope"349 endif350 endif351 else352 echohl WarningMsg | echo ""Obj_Name"is up to date"353 endif354 elseif expand("%:e") == "java"355 let class = expand("%:p:r").s:Class_Extension356 let class_Name = expand("%:p:t:r").s:Class_Extension357 if !filereadable(class) || (filereadable(class) && (getftime(class) < getftime(Sou)))358 redraw!359 exe ":setlocal makeprg=".s:JavaFlags360 echohl WarningMsg | echo " compiling..."361 silent make362 redraw!363 if v:shell_error != 0364 let s:LastShellReturn_C = v:shell_error365 endif366 if g:iswindows367 if s:LastShellReturn_C != 0368 exe ":bo cope"369 echohl WarningMsg | echo " compilation failed"370 else371 if s:ShowWarning372 exe ":bo cw"373 endif374 echohl WarningMsg | echo " compilation successful"375 endif376 else377 if empty(v:statusmsg)378 echohl WarningMsg | echo " compilation successful"379 else380 exe ":bo cope"381 endif382 endif383 else384 echohl WarningMsg | echo ""class_Name"is up to date"385 endif386 else387 let s:Sou_Error = 1388 echohl WarningMsg | echo " please choose the correct source file"389 endif390 exe ":setlocal makeprg=make"391 endfunc392 393 func! Link()394 call Compile()395 if s:Sou_Error || s:LastShellReturn_C != 0396 return397 endif398 if expand("%:e") == "c" || expand("%:e") == "cpp" || expand("%:e") == "cxx"399 let s:LastShellReturn_L = 0400 let Sou = expand("%:p")401 let Obj = expand("%:p:r").s:Obj_Extension402 if g:iswindows403 let Exe = expand("%:p:r").s:Exe_Extension404 let Exe_Name = expand("%:p:t:r").s:Exe_Extension405 else406 let Exe = expand("%:p:r")407 let Exe_Name = expand("%:p:t:r")408 endif409 let v:statusmsg = ''410 if filereadable(Obj) && (getftime(Obj) >= getftime(Sou))411 redraw!412 if !executable(Exe) || (executable(Exe) && getftime(Exe) < getftime(Obj))413 if expand("%:e") == "c"414 setlocal makeprg=gcc\ -o\ %<\ %<.o415 echohl WarningMsg | echo " linking..."416 silent make417 elseif expand("%:e") == "cpp" || expand("%:e") == "cxx"418 setlocal makeprg=g++\ -o\ %<\ %<.o419 echohl WarningMsg | echo " linking..."420 silent make421 endif422 redraw!423 if v:shell_error != 0424 let s:LastShellReturn_L = v:shell_error425 endif426 if g:iswindows427 if s:LastShellReturn_L != 0428 exe ":bo cope"429 echohl WarningMsg | echo " linking failed"430 else431 if s:ShowWarning432 exe ":bo cw"433 endif434 echohl WarningMsg | echo " linking successful"435 endif436 else437 if empty(v:statusmsg)438 echohl WarningMsg | echo " linking successful"439 else440 exe ":bo cope"441 endif442 endif443 else444 echohl WarningMsg | echo ""Exe_Name"is up to date"445 endif446 endif447 setlocal makeprg=make448 elseif expand("%:e") == "java"449 return450 endif451 endfunc452 453 func! Run()454 let s:ShowWarning = 0455 call Link()456 let s:ShowWarning = 1457 if s:Sou_Error || s:LastShellReturn_C != 0 || s:LastShellReturn_L != 0458 return459 endif460 let Sou = expand("%:p")461 if expand("%:e") == "c" || expand("%:e") == "cpp" || expand("%:e") == "cxx"462 let Obj = expand("%:p:r").s:Obj_Extension463 if g:iswindows464 let Exe = expand("%:p:r").s:Exe_Extension465 else466 let Exe = expand("%:p:r")467 endif468 if executable(Exe) && getftime(Exe) >= getftime(Obj) && getftime(Obj) >= getftime(Sou)469 redraw!470 echohl WarningMsg | echo " running..."471 if g:iswindows472 exe ":!%<.exe"473 else474 if g:isGUI475 exe ":!gnome-terminal -x bash -c './%<; echo; echo 请按 Enter 键继续; read'"476 else477 exe ":!clear; ./%<"478 endif479 endif480 redraw!481 echohl WarningMsg | echo " running finish"482 endif483 elseif expand("%:e") == "java"484 let class = expand("%:p:r").s:Class_Extension485 if getftime(class) >= getftime(Sou)486 redraw!487 echohl WarningMsg | echo " running..."488 if g:iswindows489 exe ":!java %<"490 else491 if g:isGUI492 exe ":!gnome-terminal -x bash -c 'java %<; echo; echo 请按 Enter 键继续; read'"493 else494 exe ":!clear; java %<"495 endif496 endif497 redraw!498 echohl WarningMsg | echo " running finish"499 endif500 endif501 endfunc502 503 504 " -----------------------------------------------------------------------------505 " < 在浏览器中预览 Html 或 PHP 文件 >506 " -----------------------------------------------------------------------------507 " 修改前请先通读此模块,明白了再改以避免错误508 509 " F5 加浏览器名称缩写调用浏览器预览,启用前先确定有安装相应浏览器,并在下面的配置好其安装目录510 if g:iswindows511 "以下为只支持Windows系统的浏览器512 513 " 调用系统IE浏览器预览,如果已卸载可将其注释514 nmap ie :call ViewInBrowser("ie") 515 imap ie :call ViewInBrowser("ie") 516 517 " 调用IETester(IE测试工具)预览,如果有安装可取消注释518 " nmap ie6 :call ViewInBrowser("ie6") 519 " imap ie6 :call ViewInBrowser("ie6") 520 " nmap ie7 :call ViewInBrowser("ie7") 521 " imap ie7 :call ViewInBrowser("ie7") 522 " nmap ie8 :call ViewInBrowser("ie8") 523 " imap ie8 :call ViewInBrowser("ie8") 524 " nmap ie9 :call ViewInBrowser("ie9") 525 " imap ie9 :call ViewInBrowser("ie9") 526 " nmap ie10 :call ViewInBrowser("ie10") 527 " imap ie10 :call ViewInBrowser("ie10") 528 " nmap iea :call ViewInBrowser("iea") 529 " imap iea :call ViewInBrowser("iea") 530 elseif g:islinux531 "以下为只支持Linux系统的浏览器532 "暂未配置,待有时间再弄了533 endif534 535 "以下为支持Windows与Linux系统的浏览器536 537 " 调用Firefox浏览器预览,如果有安装可取消注释538 " nmap ff :call ViewInBrowser("ff") 539 " imap ff :call ViewInBrowser("ff") 540 541 " 调用Maxthon(遨游)浏览器预览,如果有安装可取消注释542 " nmap ay :call ViewInBrowser("ay") 543 " imap ay :call ViewInBrowser("ay") 544 545 " 调用Opera浏览器预览,如果有安装可取消注释546 " nmap op :call ViewInBrowser("op") 547 " imap op :call ViewInBrowser("op") 548 549 " 调用Chrome浏览器预览,如果有安装可取消注释550 " nmap cr :call ViewInBrowser("cr") 551 " imap cr :call ViewInBrowser("cr") 552 553 " 浏览器调用函数554 function! ViewInBrowser(name)555 if expand("%:e") == "php" || expand("%:e") == "html"556 exe ":update"557 if g:iswindows558 "获取要预览的文件路径,并将路径中的'\'替换为'/',同时将路径文字的编码转换为gbk(同cp936)559 let file = iconv(substitute(expand("%:p"), '\', '/', "g"), "utf-8", "gbk")560 561 "浏览器路径设置,路径中使用'/'斜杠,更改路径请更改双引号里的内容562 "下面只启用了系统IE浏览器,如需启用其它的可将其取消注释(得先安装,并配置好安装路径),也可按需增减563 let SystemIE = "C:/progra~1/intern~1/iexplore.exe" "系统自带IE目录564 " let IETester = "F:/IETester/IETester.exe" "IETester程序目录(可按实际更改)565 " let Chrome = "F:/Chrome/Chrome.exe" "Chrome程序目录(可按实际更改)566 " let Firefox = "F:/Firefox/Firefox.exe" "Firefox程序目录(可按实际更改)567 " let Opera = "F:/Opera/opera.exe" "Opera程序目录(可按实际更改)568 " let Maxthon = "C:/Progra~2/Maxthon/Bin/Maxthon.exe" "Maxthon程序目录(可按实际更改)569 570 "本地虚拟服务器设置,我测试的是phpStudy2014,可根据自己的修改,更改路径请更改双引号里的内容571 let htdocs ="F:/phpStudy2014/WWW/" "虚拟服务器地址或目录(可按实际更改)572 let url = "localhost" "虚拟服务器网址(可按实际更改)573 elseif g:islinux574 "暂时还没有配置,有时间再弄了。575 endif576 577 "浏览器调用缩写,可根据实际增减,注意,上面浏览器路径中没有定义过的变量(等号右边为变量)不能出现在下面哟(可将其注释或删除)578 let l:browsers = {} "定义缩写字典变量,此行不能删除或注释579 " let l:browsers["cr"] = Chrome "Chrome浏览器缩写580 " let l:browsers["ff"] = Firefox "Firefox浏览器缩写581 " let l:browsers["op"] = Opera "Opera浏览器缩写582 " let l:browsers["ay"] = Maxthon "遨游浏览器缩写583 let l:browsers["ie"] = SystemIE "系统IE浏览器缩写584 " let l:browsers["ie6"] = IETester."-ie6" "调用IETESTER工具以IE6预览缩写(变量加参数)585 " let l:browsers["ie7"] = IETester."-ie7" "调用IETESTER工具以IE7预览缩写(变量加参数)586 " let l:browsers["ie8"] = IETester."-ie8" "调用IETESTER工具以IE8预览缩写(变量加参数)587 " let l:browsers["ie9"] = IETester."-ie9" "调用IETESTER工具以IE9预览缩写(变量加参数)588 " let l:browsers["ie10"] = IETester."-ie10" "调用IETESTER工具以IE10预览缩写(变量加参数)589 " let l:browsers["iea"] = IETester."-al" "调用IETESTER工具以支持的所有IE版本预览缩写(变量加参数)590 591 if stridx(file, htdocs) == -1 "文件不在本地虚拟服务器目录,则直接预览(但不能解析PHP文件)592 exec ":silent !start ". l:browsers[a:name] ." file://" . file593 else "文件在本地虚拟服务器目录,则调用本地虚拟服务器解析预览(先启动本地虚拟服务器)594 let file = substitute(file, htdocs, "http://".url."/", "g") "转换文件路径为虚拟服务器网址路径595 exec ":silent !start ". l:browsers[a:name] file596 endif597 else598 echohl WarningMsg | echo " please choose the correct source file"599 endif600 endfunction601 602 " -----------------------------------------------------------------------------603 " < 其它配置 >604 " -----------------------------------------------------------------------------605 set writebackup "保存文件前建立备份,保存成功后删除该备份606 set nobackup "设置无备份文件607 " set noswapfile "设置无临时文件608 " set vb t_vb= "关闭提示音609 610 611 " =============================================================================612 " << 以下为常用插件配置 >>613 " =============================================================================614 615 " -----------------------------------------------------------------------------616 " < a.vim 插件配置 >617 " -----------------------------------------------------------------------------618 " 用于切换C/C++头文件619 " :A ---切换头文件并独占整个窗口620 " :AV ---切换头文件并垂直分割窗口621 " :AS ---切换头文件并水平分割窗口622 623 " -----------------------------------------------------------------------------624 " < Align 插件配置 >625 " -----------------------------------------------------------------------------626 " 一个对齐的插件,用来——排版与对齐代码,功能强大,不过用到的机会不多627 628 " -----------------------------------------------------------------------------629 " < auto-pairs 插件配置 >630 " -----------------------------------------------------------------------------631 " 用于括号与引号自动补全,不过会与函数原型提示插件echofunc冲突632 " 所以我就没有加入echofunc插件633 634 " -----------------------------------------------------------------------------635 " < BufExplorer 插件配置 >636 " -----------------------------------------------------------------------------637 " 快速轻松的在缓存中切换(相当于另一种多个文件间的切换方式)638 " be 在当前窗口显示缓存列表并打开选定文件639 " bs 水平分割窗口显示缓存列表,并在缓存列表窗口中打开选定文件640 " bv 垂直分割窗口显示缓存列表,并在缓存列表窗口中打开选定文件641 642 " -----------------------------------------------------------------------------643 " < ccvext.vim 插件配置 >644 " -----------------------------------------------------------------------------645 " 用于对指定文件自动生成tags与cscope文件并连接646 " 如果是Windows系统, 则生成的文件在源文件所在盘符根目录的.symbs目录下(如: X:\.symbs\)647 " 如果是Linux系统, 则生成的文件在~/.symbs/目录下648 " 具体用法可参考www.vim.org中此插件的说明649 " sy 自动生成tags与cscope文件并连接650 " sc 连接已存在的tags与cscope文件651 652 " -----------------------------------------------------------------------------653 " < cSyntaxAfter 插件配置 >654 " -----------------------------------------------------------------------------655 " 高亮括号与运算符等656 au! BufRead,BufNewFile,BufEnter *.{c,cpp,h,java,javascript} call CSyntaxAfter()657 658 " -----------------------------------------------------------------------------659 " < ctrlp.vim 插件配置 >660 " -----------------------------------------------------------------------------661 " 一个全路径模糊文件,缓冲区,最近最多使用,... 检索插件;详细帮助见 :h ctrlp662 " 常规模式下输入:Ctrl + p 调用插件663 664 " -----------------------------------------------------------------------------665 " < emmet-vim(前身为Zen coding) 插件配置 >666 " -----------------------------------------------------------------------------667 " HTML/CSS代码快速编写神器,详细帮助见 :h emmet.txt668 669 " -----------------------------------------------------------------------------670 " < indentLine 插件配置 >671 " -----------------------------------------------------------------------------672 " 用于显示对齐线,与 indent_guides 在显示方式上不同,根据自己喜好选择了673 " 在终端上会有屏幕刷新的问题,这个问题能解决有更好了674 " 开启/关闭对齐线675 nmap il :IndentLinesToggle 676 677 " 设置Gvim的对齐线样式678 if g:isGUI679 let g:indentLine_char = "┊"680 let g:indentLine_first_char = "┊"681 endif682 683 " 设置终端对齐线颜色,如果不喜欢可以将其注释掉采用默认颜色684 let g:indentLine_color_term = 239685 686 " 设置 GUI 对齐线颜色,如果不喜欢可以将其注释掉采用默认颜色687 " let g:indentLine_color_gui = '#A4E57E'688 689 " -----------------------------------------------------------------------------690 " < vim-javacompleteex(也就是 javacomplete 增强版)插件配置 >691 " -----------------------------------------------------------------------------692 " java 补全插件693 694 " -----------------------------------------------------------------------------695 " < Mark--Karkat(也就是 Mark) 插件配置 >696 " -----------------------------------------------------------------------------697 " 给不同的单词高亮,表明不同的变量时很有用,详细帮助见 :h mark.txt698 699 " " -----------------------------------------------------------------------------700 " " < MiniBufExplorer 插件配置 >701 " " -----------------------------------------------------------------------------702 " " 快速浏览和操作Buffer703 " " 主要用于同时打开多个文件并相与切换704 705 " " let g:miniBufExplMapWindowNavArrows = 1 "用Ctrl加方向键切换到上下左右的窗口中去706 " let g:miniBufExplMapWindowNavVim = 1 "用 切换到上下左右的窗口中去707 " let g:miniBufExplMapCTabSwitchBufs = 1 "功能增强(不过好像只有在Windows中才有用)708 " " 向前循环切换到每个buffer上,并在但前窗口打开709 " " 向后循环切换到每个buffer上,并在当前窗口打开710 711 " 在不使用 MiniBufExplorer 插件时也可用 切换到上下左右的窗口中去712 noremap k713 noremap j714 noremap h715 noremap l716 717 " -----------------------------------------------------------------------------718 " < neocomplcache 插件配置 >719 " -----------------------------------------------------------------------------720 " 关键字补全、文件路径补全、tag补全等等,各种,非常好用,速度超快。721 let g:neocomplcache_enable_at_startup = 1 "vim 启动时启用插件722 " let g:neocomplcache_disable_auto_complete = 1 "不自动弹出补全列表723 " 在弹出补全列表后用 或 进行上下选择效果比较好724 725 " -----------------------------------------------------------------------------726 " < nerdcommenter 插件配置 >727 " -----------------------------------------------------------------------------728 " 我主要用于C/C++代码注释(其它的也行)729 " 以下为插件默认快捷键,其中的说明是以C/C++为例的,其它语言类似730 " ci 以每行一个 /* */ 注释选中行(选中区域所在行),再输入则取消注释731 " cm 以一个 /* */ 注释选中行(选中区域所在行),再输入则称重复注释732 " cc 以每行一个 /* */ 注释选中行或区域,再输入则称重复注释733 " cu 取消选中区域(行)的注释,选中区域(行)内至少有一个 /* */734 " ca 在/*...*/与//这两种注释方式中切换(其它语言可能不一样了)735 " cA 行尾注释736 let NERDSpaceDelims = 1 "在左注释符之后,右注释符之前留有空格737 738 " -----------------------------------------------------------------------------739 " < nerdtree 插件配置 >740 " -----------------------------------------------------------------------------741 " 有目录村结构的文件浏览插件742 743 " 常规模式下输入 F2 调用插件744 nmap :NERDTreeToggle 745 746 " -----------------------------------------------------------------------------747 " < omnicppcomplete 插件配置 >748 " -----------------------------------------------------------------------------749 " 用于C/C++代码补全,这种补全主要针对命名空间、类、结构、共同体等进行补全,详细750 " 说明可以参考帮助或网络教程等751 " 使用前先执行如下 ctags 命令(本配置中可以直接使用 ccvext 插件来执行以下命令)752 " ctags -R --c++-kinds=+p --fields=+iaS --extra=+q753 " 我使用上面的参数生成标签后,对函数使用跳转时会出现多个选择754 " 所以我就将--c++-kinds=+p参数给去掉了,如果大侠有什么其它解决方法希望不要保留呀755 set completeopt=menu "关闭预览窗口756 757 " -----------------------------------------------------------------------------758 " < powerline 插件配置 >759 " -----------------------------------------------------------------------------760 " 状态栏插件,更好的状态栏效果761 762 " -----------------------------------------------------------------------------763 " < repeat 插件配置 >764 " -----------------------------------------------------------------------------765 " 主要用"."命令来重复上次插件使用的命令766 767 " -----------------------------------------------------------------------------768 " < snipMate 插件配置 >769 " -----------------------------------------------------------------------------770 " 用于各种代码补全,这种补全是一种对代码中的词与代码块的缩写补全,详细用法可以参771 " 考使用说明或网络教程等。不过有时候也会与 supertab 插件在补全时产生冲突,如果大772 " 侠有什么其它解决方法希望不要保留呀773 774 " -----------------------------------------------------------------------------775 " < SrcExpl 插件配置 >776 " -----------------------------------------------------------------------------777 " 增强源代码浏览,其功能就像Windows中的"Source Insight"778 nmap :SrcExplToggle "打开/闭浏览窗口779 780 " -----------------------------------------------------------------------------781 " < std_c 插件配置 >782 " -----------------------------------------------------------------------------783 " 用于增强C语法高亮784 785 " 启用 // 注视风格786 let c_cpp_comments = 0787 788 " -----------------------------------------------------------------------------789 " < surround 插件配置 >790 " -----------------------------------------------------------------------------791 " 快速给单词/句子两边增加符号(包括html标签),缺点是不能用"."来重复命令792 " 不过 repeat 插件可以解决这个问题,详细帮助见 :h surround.txt793 794 " -----------------------------------------------------------------------------795 " < Syntastic 插件配置 >796 " -----------------------------------------------------------------------------797 " 用于保存文件时查检语法798 799 " -----------------------------------------------------------------------------800 " < Tagbar 插件配置 >801 " -----------------------------------------------------------------------------802 " 相对 TagList 能更好的支持面向对象803 804 " 常规模式下输入 tb 调用插件,如果有打开 TagList 窗口则先将其关闭805 nmap tb :TlistClose :TagbarToggle 806 807 let g:tagbar_width=30 "设置窗口宽度808 " let g:tagbar_left=1 "在左侧窗口中显示809 810 " -----------------------------------------------------------------------------811 " < TagList 插件配置 >812 " -----------------------------------------------------------------------------813 " 高效地浏览源码, 其功能就像vc中的workpace814 " 那里面列出了当前文件中的所有宏,全局变量, 函数名等815 816 " 常规模式下输入 tl 调用插件,如果有打开 Tagbar 窗口则先将其关闭817 nmap tl :TagbarClose :Tlist 818 819 let Tlist_Show_One_File=1 "只显示当前文件的tags820 " let Tlist_Enable_Fold_Column=0 "使taglist插件不显示左边的折叠行821 let Tlist_Exit_OnlyWindow=1 "如果Taglist窗口是最后一个窗口则退出Vim822 let Tlist_File_Fold_Auto_Close=1 "自动折叠823 let Tlist_WinWidth=30 "设置窗口宽度824 let Tlist_Use_Right_Window=1 "在右侧窗口中显示825 826 " -----------------------------------------------------------------------------827 " < txtbrowser 插件配置 >828 " -----------------------------------------------------------------------------829 " 用于文本文件生成标签与与语法高亮(调用TagList插件生成标签,如果可以)830 au BufRead,BufNewFile *.txt setlocal ft=txt831 832 " -----------------------------------------------------------------------------833 " < ZoomWin 插件配置 >834 " -----------------------------------------------------------------------------835 " 用于分割窗口的最大化与还原836 " 常规模式下按快捷键 o 在最大化与还原间切换837 838 " =============================================================================839 " << 以下为常用工具配置 >>840 " =============================================================================841 842 " -----------------------------------------------------------------------------843 " < cscope 工具配置 >844 " -----------------------------------------------------------------------------845 " 用Cscope自己的话说 - "你可以把它当做是超过频的ctags"846 if has("cscope")847 "设定可以使用 quickfix 窗口来查看 cscope 结果848 set cscopequickfix=s-,c-,d-,i-,t-,e-849 "使支持用 Ctrl+] 和 Ctrl+t 快捷键在代码间跳转850 set cscopetag851 "如果你想反向搜索顺序设置为1852 set csto=0853 "在当前目录中添加任何数据库854 if filereadable("cscope.out")855 cs add cscope.out856 "否则添加数据库环境中所指出的857 elseif $CSCOPE_DB != ""858 cs add $CSCOPE_DB859 endif860 set cscopeverbose861 "快捷键设置862 nmap s :cs find s =expand(" ") 863 nmap g :cs find g =expand(" ") 864 nmap c :cs find c =expand(" ") 865 nmap t :cs find t =expand(" ") 866 nmap e :cs find e =expand(" ") 867 nmap f :cs find f =expand(" ") 868 nmap i :cs find i ^ =expand(" ") $ 869 nmap d :cs find d =expand(" ") 870 endif871 872 " -----------------------------------------------------------------------------873 " < ctags 工具配置 >874 " -----------------------------------------------------------------------------875 " 对浏览代码非常的方便,可以在函数,变量之间跳转等876 set tags=./tags; "向上级目录递归查找tags文件(好像只有在Windows下才有用)877 878 " -----------------------------------------------------------------------------879 " < gvimfullscreen 工具配置 > 请确保已安装了工具880 " -----------------------------------------------------------------------------881 " 用于 Windows Gvim 全屏窗口,可用 F11 切换882 " 全屏后再隐藏菜单栏、工具栏、滚动条效果更好883 if (g:iswindows && g:isGUI)884 nmap :call libcallnr("gvimfullscreen.dll", "ToggleFullScreen", 0) 885 endif886 887 " -----------------------------------------------------------------------------888 " < vimtweak 工具配置 > 请确保以已装了工具889 " -----------------------------------------------------------------------------890 " 这里只用于窗口透明与置顶891 " 常规模式下 Ctrl + Up(上方向键) 增加不透明度,Ctrl + Down(下方向键) 减少不透明度, t 窗口置顶与否切换892 if (g:iswindows && g:isGUI)893 let g:Current_Alpha = 255894 let g:Top_Most = 0895 func! Alpha_add()896 let g:Current_Alpha = g:Current_Alpha + 10897 if g:Current_Alpha > 255898 let g:Current_Alpha = 255899 endif900 call libcallnr("vimtweak.dll","SetAlpha",g:Current_Alpha)901 endfunc902 func! Alpha_sub()903 let g:Current_Alpha = g:Current_Alpha - 10904 if g:Current_Alpha < 155905 let g:Current_Alpha = 155906 endif907 call libcallnr("vimtweak.dll","SetAlpha",g:Current_Alpha)908 endfunc909 func! Top_window()910 if g:Top_Most == 0911 call libcallnr("vimtweak.dll","EnableTopMost",1)912 let g:Top_Most = 1913 else914 call libcallnr("vimtweak.dll","EnableTopMost",0)915 let g:Top_Most = 0916 endif917 endfunc918 919 "快捷键设置920 nmap :call Alpha_add() 921 nmap :call Alpha_sub() 922 nmap t :call Top_window() 923 endif924 925 " =============================================================================926 " << 以下为常用自动命令配置 >>927 " =============================================================================928 929 " 自动切换目录为当前编辑文件所在目录930 au BufRead,BufNewFile,BufEnter * cd %:p:h931 932 " =============================================================================933 " << windows 下解决 Quickfix 乱码问题 >>934 " =============================================================================935 " windows 默认编码为 cp936,而 Gvim(Vim) 内部编码为 utf-8,所以常常输出为乱码936 " 以下代码可以将编码为 cp936 的输出信息转换为 utf-8 编码,以解决输出乱码问题937 " 但好像只对输出信息全部为中文才有满意的效果,如果输出信息是中英混合的,那可能938 " 不成功,会造成其中一种语言乱码,输出信息全部为英文的好像不会乱码939 " 如果输出信息为乱码的可以试一下下面的代码,如果不行就还是给它注释掉940 941 " if g:iswindows942 " function QfMakeConv()943 " let qflist = getqflist()944 " for i in qflist945 " let i.text = iconv(i.text, "cp936", "utf-8")946 " endfor947 " call setqflist(qflist)948 " endfunction949 " au QuickfixCmdPost make call QfMakeConv()950 " endif951 952 " =============================================================================953 " << 其它 >>954 " =============================================================================955 " 注:上面配置中的" "在本软件中设置为"\"键(引号里的反斜杠),如 t956 " 指在常规模式下按"\"键加"t"键,这里不是同时按,而是先按"\"键后按"t"键,间隔在一957 " 秒内,而 cs是先按"\"键再按"c"又再按"s"键;如要修改" "键,可以把958 " 下面的设置取消注释,并修改双引号中的键为你想要的,如修改为逗号键。959 960 "
3.在gvim中下载插件
:BundleInstall
基本设置完成
具体设置可见