vim使用Vundle一键配置完美php IDE开发环境
作者:我不叫大脸猫 发布于:2013-4-11 10:33 Thursday 分类:php
Vundle是一款基于git的vim插件管理工具,通过git一键安装各类常用vim插件,你只需要将.vimrc文件保存在云上,随时随地一键配置强大的vim开发工具.
Vundle安装灰常简单,只需要一个git命令:
接下来就是配置你的vim,在$HOME(linux上是你当前用户的家目录,windows上是C:\windows\users\ooxx)目录下创建或打开.vimrc,写入(这是我的独家配置哦):
001 | <pre class= "brush:shell; toolbar: true; auto-links: true;" > set nocompatible |
003 | set rtp+=$HOME/.vim/bundle/vundle/ |
004 | set rtp+=$HOME/.vim/Bundle/Tagbar/ |
006 | Bundle 'gmarik/vundle' |
007 | source $VIMRUNTIME/vimrc_example.vim |
008 | source $VIMRUNTIME/mswin.vim |
011 | " Multi-encoding setting, MUST BE IN THE BEGINNING OF .vimrc! |
014 | " When 'fileencodings' starts with 'ucs-bom' , don't do this manually |
016 | set fileencodings=ucs-bom,utf-8,chinese,taiwan,japan,korea,latin1 |
017 | " CJK environment detection and corresponding setting |
018 | if v :lang =~ "^zh_CN" |
019 | " Simplified Chinese, on Unix euc-cn, on MS-Windows cp936 |
021 | set termencoding=chinese |
022 | if &fileencoding == '' |
023 | set fileencoding=chinese |
025 | elseif v :lang =~ "^zh_TW" |
026 | " Traditional Chinese, on Unix euc-tw, on MS-Windows cp950 |
028 | set termencoding=taiwan |
029 | if &fileencoding == '' |
030 | set fileencoding=taiwan |
032 | elseif v :lang =~ "^ja_JP" |
033 | " Japanese, on Unix euc-jp, on MS-Windows cp932 |
035 | set termencoding=japan |
036 | if &fileencoding == '' |
037 | set fileencoding=japan |
039 | elseif v :lang =~ "^ko" |
040 | " Korean on Unix euc-kr, on MS-Windows cp949 |
042 | set termencoding=korea |
043 | if &fileencoding == '' |
044 | set fileencoding=korea |
047 | " Detect UTF-8 locale, and override CJK setting if needed |
048 | if v :lang =~ "utf8$" || v :lang =~ "UTF-8$" |
052 | echoerr 'Sorry, this version of (g)Vim was not compiled with "multi_byte"' |
055 | set diffexpr=MyDiff() |
057 | let opt = '-a --binary ' |
058 | if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif |
059 | if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif |
060 | let arg1 = v :fname_in |
061 | if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif |
062 | let arg2 = v :fname_new |
063 | if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif |
064 | let arg3 = v :fname_out |
065 | if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif |
067 | if $VIMRUNTIME =~ ' ' |
069 | let cmd = '""' . $VIMRUNTIME . '\diff"' |
072 | let cmd = substitute($VIMRUNTIME, ' ' , '" ' , '' ) . '\diff"' |
075 | let cmd = $VIMRUNTIME . '\diff' |
077 | silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq |
084 | filetype plugin indent on |
091 | "设置 Backspace 和 Delete 的灵活程度,backspace=2 则没有任何限制 |
092 | "设置在哪些模式下使用鼠标功能,mouse=a 表示所有模式 |
100 | "au BufWinEnter * let w:m2=matchadd( 'Underlined' , '\%>100v.\+' , -1) |
101 | "syn match out80 /\%80v./ containedin=ALL |
102 | "hi out80 guifg=white guibg=red |
114 | set cindent shiftwidth=4 |
115 | " set autoindent shiftwidth=2 |
141 | "启动的时候不显示那个援助索马里儿童的提示 |
147 | " 不要生成swap文件,当buffer被丢弃的时候隐藏它 |
153 | " set listchars=tab:>-,trail:- |
156 | set laststatus=2 "显示状态栏(默认值为1, 无法显示状态栏) |
158 | set statusline+=%2*%-3.3n%0*\ " buffer number |
159 | set statusline+=%f\ " file name |
160 | set statusline+=%h%1*%m%r%w%0* " flag |
163 | set statusline+=%{strlen(&ft)?&ft: 'none' }, " filetype |
164 | set statusline+=%{&fileencoding}, " encoding |
166 | set statusline+=%{&fileformat}] " file format |
167 | set statusline+=%= " right align |
168 | "set statusline+=%2*0x%-8B\ " current char |
169 | set statusline+=0x%-8B\ " current char |
170 | set statusline+=%-14.(%l,%c%V%)\ %<%P " offset |
171 | if filereadable( expand ( "$VIM/vimfiles/plugin/vimbuddy.vim" )) |
172 | set statusline+=\ %{VimBuddy()} " vim buddy |
178 | "执行 Vim 缺省提供的 .vimrc 文件的示例,包含了打开语法加亮显示等最常用的功能 |
179 | source $VIMRUNTIME/vimrc_example.vim |
185 | "在输入括号时光标会短暂地跳到与之相匹配的括号处,不影响输入 |
188 | set formatoptions+=mM |
198 | hi link phpheredoc string |
204 | autocmd BufEnter * exec "cd %:p:h" |
207 | set fileformats=dos,unix |
210 | "colorscheme peacock_light |
211 | colorscheme peacock_desert |
214 | au GUIEnter * simalt ~x |
216 | "置粘贴模式,这样粘贴过来的程序代码就不会错位了。 |
220 | set viminfo='10,\"100,:20,%,n$VIMRUNTIME/_viminfo |
221 | au BufReadPost * if line( "'\"" ) > 0| if line( "'\"" ) <= line( "$" )|exe( "norm '\"" )| else |exe "norm $" |endif|endif |
222 | "autocmd BufWinLeave * if expand ( '%' ) != '' && &buftype == '' | mkview | endif |
223 | "autocmd BufRead * if expand ( '%' ) != '' && &buftype == '' | silent loadview | syntax on | endif |
225 | "You can obtain the completion dictionary file from: |
227 | " set dictionary+=$VIM\vimfiles\syntax\ function .txt |
228 | au FileType php setlocal dictionary+=$VIM\vimfiles\syntax\ function .txt |
230 | if !exists( 'g:AutoComplPop_Behavior' ) |
231 | let g:AutoComplPop_Behavior = {} |
232 | let g:AutoComplPop_Behavior[ 'php' ] = [] |
233 | call add(g:AutoComplPop_Behavior[ 'php' ], { |
234 | \ 'command' : "\<C-x>\<C-o>" , |
235 | \ 'pattern' : printf ( '\(->\|::\|\$\)\k\{%d,}$' , 0), |
241 | :inoremap ) <c-r>=ClosePair( ')' )<CR> |
243 | :inoremap } <c-r>=ClosePair( '}' )<CR> |
245 | :inoremap ] <c-r>=ClosePair( ']' )<CR> |
247 | :inoremap > <c-r>=ClosePair( '>' )<CR> |
249 | function ! ClosePair(char) |
250 | if getline( '.' )[col( '.' ) - 1] == a:char |
257 | "Use the dictionary completion |
258 | " set complete-=k complete+=k |
260 | "html自动输入匹配标签,输入>之后自动完成匹配标签 |
261 | "au FileType xhtml,xml so ~/.vim/ftplugin/html_autoclosetag.vim |
263 | "F7单独切换打开nerd_tree(nerd_tree插件) |
264 | let g:NERDChristmasTree = 1 "色彩显示 |
265 | let g:NERDTreeShowHidden = 1 "显示隐藏文件 |
266 | let g:NERDTreeWinPos = 'left' "窗口显示位置 |
267 | let g:NERDTreeHighlightCursorline = 0 "高亮当前行 |
268 | nmap <C-F4> :NERDTree<CR> |
270 | let g:SuperTabRetainCompletionType = 2 |
271 | let g:SuperTabDefaultCompletionType = "<C-X><C-O>" |
274 | function ! GetSystem() |
275 | if (has( "win32" ) || has( "win95" ) || has( "win64" ) || has( "win16" )) |
284 | "F8单独切换打开taglist(taglist插件) |
285 | if GetSystem() == "windows" |
286 | let g:Tlist_Ctags_Cmd = $VIMRUNTIME. '\ctags' |
288 | let g:Tlist_Ctags_Cmd = '/usr/bin/ctags' |
290 | "let g:Tlist_Sort_Type = 'name' " 以名称顺序排序,默认以位置顺序(order) |
291 | "let g:Tlist_Show_One_File = 1 " 不同时显示多个文件的tag,只显示当前文件的 |
292 | "let g:Tlist_Exit_OnlyWindow = 1 " 如果taglist窗口是最后一个窗口,则退出vim |
293 | "lef g:Tlist_File_Fold_Auto_Close = 1 " 当光标不在编辑文件里面的时候全部折叠 |
294 | "let g:Tlist_Use_Right_Window = 1 " 在右侧窗口中显示taglist窗口 |
295 | "let g:Tlist_Enable_Fold_Column = 1 " 显示折叠边栏 |
296 | "nmap <C-F8> :TlistToggle<CR> |
302 | "Ctrl + F12删除&&更新tags文件 |
303 | function ! DeleteTagsFile() |
307 | silent !del /F /Q tags |
308 | silent !ctags -R --languages=php,c --c-kinds=+p --fields=+ianS --extra=+q |
310 | nmap <C-F12> :call DeleteTagsFile()<CR> |
312 | "au VimLeavePre * call DeleteTagsFile() |
314 | "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" |
316 | "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" |
317 | let g:LookupFile_MinPatLength = 2 "最少输入2个字符才开始查找 |
318 | let g:LookupFile_PreserveLastPattern = 0 "不保存上次查找的字符串 |
319 | let g:LookupFile_PreservePatternHistory = 1 "保存查找历史 |
320 | let g:LookupFile_AlwaysAcceptFirst = 1 "回车打开第一个匹配项目 |
321 | let g:LookupFile_AllowNewFiles = 0 "不允许创建不存在的文件 |
322 | if filereadable( "./filenametags" ) "设置tag文件的名字 |
323 | let g:LookupFile_TagExpr = '"./filenametags"' |
327 | nmap <silent> <leader>lk :LUTags<cr> |
329 | nmap <silent> <leader>ll :LUBufs<cr> |
331 | nmap <silent> <leader>lw :LUWalk<cr> |
333 | let g:indent_guides_guide_size=1 |
340 | let g:tagbar_ctags_bin = 'ctags' |
341 | let g:tagbar_width = 30 |
342 | nmap <C-F5> :TagbarToggle<CR> |
343 | nmap <C-F6> :Bufferlist<CR> |
345 | set display=lastline</pre><br> |
接下来保存.vimrc,在vim命令模式中执行source命令引入当前的配置,接着执行:BundleInstall命令,执行结果如图:
![点击查看原图](http://www.ballooncat.com/content/uploadfile/201304/thum-8d841365649160.jpg)
酱紫就大功告成了.