vim使用Vundle一键配置完美php IDE开发环境

vim使用Vundle一键配置完美php IDE开发环境

作者:我不叫大脸猫 发布于:2013-4-11 10:33 Thursday 分类:php

Vundle是一款基于git的vim插件管理工具,通过git一键安装各类常用vim插件,你只需要将.vimrc文件保存在云上,随时随地一键配置强大的vim开发工具.

 

Vundle安装灰常简单,只需要一个git命令:

1 $ git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
接下来就是配置你的vim,在$HOME(linux上是你当前用户的家目录,windows上是C:\windows\users\ooxx)目录下创建或打开.vimrc,写入(这是我的独家配置哦):

001 <pre class="brush:shell; toolbar: true; auto-links: true;">set nocompatible
002 filetype off
003 set rtp+=$HOME/.vim/bundle/vundle/
004 set rtp+=$HOME/.vim/Bundle/Tagbar/
005 call vundle#rc()
006 Bundle 'gmarik/vundle'
007 source $VIMRUNTIME/vimrc_example.vim
008 source $VIMRUNTIME/mswin.vim
009 behave mswin
010 set showtabline=2
011 " Multi-encoding setting, MUST BE IN THE BEGINNING OF .vimrc!
012 "
013 if has("multi_byte")
014     " When 'fileencodings' starts with 'ucs-bom', don't do this manually
015     "set bomb
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
020         set encoding=chinese
021         set termencoding=chinese
022         if &fileencoding == ''
023             set fileencoding=chinese
024         endif
025     elseif v:lang =~ "^zh_TW"
026         " Traditional Chinese, on Unix euc-tw, on MS-Windows cp950
027         set encoding=taiwan
028         set termencoding=taiwan
029         if &fileencoding == ''
030             set fileencoding=taiwan
031         endif
032     elseif v:lang =~ "^ja_JP"
033         " Japanese, on Unix euc-jp, on MS-Windows cp932
034         set encoding=japan
035         set termencoding=japan
036         if &fileencoding == ''
037             set fileencoding=japan
038         endif
039     elseif v:lang =~ "^ko"
040         " Korean on Unix euc-kr, on MS-Windows cp949
041         set encoding=korea
042         set termencoding=korea
043         if &fileencoding == ''
044             set fileencoding=korea
045         endif
046     endif
047     " Detect UTF-8 locale, and override CJK setting if needed
048     if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
049         set encoding=utf-8
050     endif
051 else
052     echoerr 'Sorry, this version of (g)Vim was not compiled with "multi_byte"'
053 endif
054  
055 set diffexpr=MyDiff()
056 function! 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
066   let eq ''
067   if $VIMRUNTIME =~ ' '
068     if &sh =~ '\<cmd'
069       let cmd = '""' . $VIMRUNTIME . '\diff"'
070       let eq '"'
071     else
072       let cmd = substitute($VIMRUNTIME, ' ''" ''') . '\diff"'
073     endif
074   else
075     let cmd = $VIMRUNTIME . '\diff'
076   endif
077   silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
078 endfunction
079  
080 "设置行号
081 set nu
082  
083 "自动检测文件类型
084 filetype plugin indent on
085  
086 "语法高亮
087 syntax on
088  
089 "自动缩进
090 set autoindent
091 "设置 Backspace 和 Delete 的灵活程度,backspace=2 则没有任何限制
092 "设置在哪些模式下使用鼠标功能,mouse=a 表示所有模式
093 set mouse=a
094 set backspace=2
095 "不自动换行
096 set nowrap
097 "设置超过100字符自动换行
098 "set textwidth=100
099 "设置超过100列的字符带下划线
100 "au BufWinEnter * let w:m2=matchadd('Underlined''\%>100v.\+', -1)
101 "syn match out80 /\%80v./ containedin=ALL
102 "hi out80 guifg=white guibg=red
103 "智能对齐方式
104 set smartindent
105 "一个tab是4个字符
106 set tabstop=4
107 "按一次tab前进4个字符
108 set softtabstop=4
109 "用空格代替tab
110 set expandtab
111 "设置自动缩进
112 set ai!
113 "缩进的字符个数
114 set cindent shiftwidth=4
115 "set autoindent shiftwidth=2
116  
117 "打开光标的行列位置显示功能
118 set ruler
119  
120 "显示中文引号
121 set ambiwidth=double
122  
123 "行高亮
124 set cursorline
125 "列高亮,与函数列表有冲突
126 set cursorcolumn
127  
128 "设置命令行的高度
129 set cmdheight=2
130  
131 "高亮搜索的关键字
132 set hlsearch
133  
134 "搜索忽略大小写
135 set ignorecase
136  
137 "设置命令历史行数
138 set history=100
139 "设置自动换行
140 set wrap
141 "启动的时候不显示那个援助索马里儿童的提示
142 set shortmess=atI
143  
144 "不要闪烁
145 "set novisualbell
146  
147 " 不要生成swap文件,当buffer被丢弃的时候隐藏它
148 setlocal noswapfile
149 set bufhidden=hide
150  
151 "显示TAB健
152 "set list
153 "set listchars=tab:>-,trail:-
154  
155 "设置VIM状态栏
156 set laststatus=2 "显示状态栏(默认值为1, 无法显示状态栏)
157 set statusline=
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
161 set statusline+=[
162 if v:version >= 600
163     set statusline+=%{strlen(&ft)?&ft:'none'}, " filetype
164     set statusline+=%{&fileencoding}, " encoding
165 endif
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
173 endif
174  
175 "增强模式中的命令行自动完成操作
176 set wildmenu
177  
178 "执行 Vim 缺省提供的 .vimrc 文件的示例,包含了打开语法加亮显示等最常用的功能
179 source $VIMRUNTIME/vimrc_example.vim
180  
181 "缺省不产生备份文件
182 set nobackup
183 set noswapfile
184 set nowritebackup
185 "在输入括号时光标会短暂地跳到与之相匹配的括号处,不影响输入
186 set showmatch
187 "正确地处理中文字符的折行和拼接
188 set formatoptions+=mM
189  
190 "设定文件浏览器目录为当前目录
191 set bsdir=buffer
192 "自动切换当前目录为当前文件所在的目录
193 set autochdir
194 "自动重新加载外部修改内容
195 "set autoread
196  
197 "使PHP识别EOT字符串
198 hi link phpheredoc string
199  
200 "允许在有未保存的修改时切换缓冲区
201 set hidden
202  
203 "进入当前编辑的文件的目录
204 autocmd BufEnter * exec "cd %:p:h"
205  
206 "保存文件的格式顺序
207 set fileformats=dos,unix
208  
209 "配色(更多的配色见colors目录和http://www.cs.cmu.edu/~maverick/VimColorSchemeTest/index-c.html)
210 "colorscheme peacock_light
211 colorscheme peacock_desert
212  
213 "启动后最大化
214 au GUIEnter * simalt ~x
215  
216 "置粘贴模式,这样粘贴过来的程序代码就不会错位了。
217 "set paste
218  
219 "记录上次关闭的文件及状态
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
224  
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
229  
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),
236             \   'repeat'    : 0,
237             \})
238 endif
239  
240 :inoremap ( ()<ESC>i
241 :inoremap ) <c-r>=ClosePair(')')<CR>
242 :inoremap { {}<ESC>i
243 :inoremap } <c-r>=ClosePair('}')<CR>
244 :inoremap [ []<ESC>i
245 :inoremap ] <c-r>=ClosePair(']')<CR>
246 :inoremap < <><ESC>i
247 :inoremap > <c-r>=ClosePair('>')<CR>
248  
249 function! ClosePair(char)
250   if getline('.')[col('.') - 1] == a:char
251     return "\<Right>"
252     else
253     return a:char
254   endif
255 endf
256  
257 "Use the dictionary completion
258 "set complete-=k complete+=k
259  
260 "html自动输入匹配标签,输入>之后自动完成匹配标签
261 "au FileType xhtml,xml so ~/.vim/ftplugin/html_autoclosetag.vim
262  
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>
269  
270 let g:SuperTabRetainCompletionType = 2
271 let g:SuperTabDefaultCompletionType = "<C-X><C-O>"
272  
273 "平台判断
274 function! GetSystem()
275     if (has("win32") || has("win95") || has("win64") || has("win16"))
276         return "windows"
277     elseif has("unix")
278         return "linux"
279     elseif has("mac")
280         return "mac"
281     endif
282 endfunction
283  
284 "F8单独切换打开taglist(taglist插件)
285 if GetSystem() == "windows"
286 let g:Tlist_Ctags_Cmd = $VIMRUNTIME.'\ctags'
287 else
288     let g:Tlist_Ctags_Cmd = '/usr/bin/ctags'
289 endif
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>
297  
298 "F12生成/更新tags文件
299 set tags=tags;
300 set autochdir
301  
302 "Ctrl + F12删除&&更新tags文件
303 function! DeleteTagsFile()
304     "Linux下的删除方法
305     "silent !rm tags
306     "Windows下的删除方法
307     silent !del /F /Q tags
308     silent !ctags -R --languages=php,c --c-kinds=+p --fields=+ianS --extra=+q
309 endfunction
310 nmap <C-F12> :call DeleteTagsFile()<CR>
311 "退出VIM之前删除tags文件
312 "au VimLeavePre * call DeleteTagsFile()
313  
314 """"""""""""""""""""""""""""""
315 " lookupfile setting
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"'
324 endif
325  
326 "映射LookupFile为,lk
327 nmap <silent> <leader>lk :LUTags<cr>
328 "映射LUBufs为,ll
329 nmap <silent> <leader>ll :LUBufs<cr>
330 "映射LUWalk为,lw
331 nmap <silent> <leader>lw :LUWalk<cr>
332 "call pathogen#infect()
333 let g:indent_guides_guide_size=1
334 set modelines=20
335 set confirm
336 "set cscopetag
337 Bundle 'DBGPavim'
338 Bundle 'Tagbar'
339 Bundle 'buffet.vim'
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>
344 set complete=t
345 set display=lastline</pre><br>

接下来保存.vimrc,在vim命令模式中执行source命令引入当前的配置,接着执行:BundleInstall命令,执行结果如图:

点击查看原图

酱紫就大功告成了.

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值