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

来源:互联网 发布:java培训育知同创 编辑:程序博客网 时间:2024/06/06 18:17

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
002filetype off
003set rtp+=$HOME/.vim/bundle/vundle/
004set rtp+=$HOME/.vim/Bundle/Tagbar/
005call vundle#rc()
006Bundle 'gmarik/vundle'
007source $VIMRUNTIME/vimrc_example.vim
008source $VIMRUNTIME/mswin.vim
009behave mswin
010set showtabline=2
011" Multi-encoding setting, MUST BE IN THE BEGINNING OF .vimrc!
012"
013if 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
051else
052    echoerr 'Sorry, this version of (g)Vim was not compiled with "multi_byte"'
053endif
054 
055set diffexpr=MyDiff()
056function! MyDiff()
057  let opt = '-a --binary '
058  if &diffopt =~ 'icase' let opt = opt . '-i ' | endif
059  if &diffopt =~ 'iwhite' let opt = opt . '-b ' | endif
060let 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
078endfunction
079 
080"设置行号
081set nu
082 
083"自动检测文件类型
084filetype plugin indent on
085 
086"语法高亮
087syntax on
088 
089"自动缩进
090set autoindent
091"设置 Backspace 和 Delete 的灵活程度,backspace=2 则没有任何限制
092"设置在哪些模式下使用鼠标功能,mouse=a 表示所有模式
093set mouse=a
094set backspace=2
095"不自动换行
096set 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"智能对齐方式
104set smartindent
105"一个tab是4个字符
106set tabstop=4
107"按一次tab前进4个字符
108set softtabstop=4
109"用空格代替tab
110set expandtab
111"设置自动缩进
112set ai!
113"缩进的字符个数
114set cindent shiftwidth=4
115"set autoindent shiftwidth=2
116 
117"打开光标的行列位置显示功能
118set ruler
119 
120"显示中文引号
121set ambiwidth=double
122 
123"行高亮
124set cursorline
125"列高亮,与函数列表有冲突
126set cursorcolumn
127 
128"设置命令行的高度
129set cmdheight=2
130 
131"高亮搜索的关键字
132set hlsearch
133 
134"搜索忽略大小写
135set ignorecase
136 
137"设置命令历史行数
138set history=100
139"设置自动换行
140set wrap
141"启动的时候不显示那个援助索马里儿童的提示
142set shortmess=atI
143 
144"不要闪烁
145"set novisualbell
146 
147" 不要生成swap文件,当buffer被丢弃的时候隐藏它
148setlocal noswapfile
149set bufhidden=hide
150 
151"显示TAB健
152"set list
153"set listchars=tab:>-,trail:-
154 
155"设置VIM状态栏
156set laststatus=2 "显示状态栏(默认值为1, 无法显示状态栏)
157set statusline=
158set statusline+=%2*%-3.3n%0*\ " buffer number
159set statusline+=%f\ " file name
160set statusline+=%h%1*%m%r%w%0* " flag
161set statusline+=[
162if v:version >= 600
163    set statusline+=%{strlen(&ft)?&ft:'none'}, " filetype
164    set statusline+=%{&fileencoding}, " encoding
165endif
166set statusline+=%{&fileformat}] " file format
167set statusline+=%= " right align
168"set statusline+=%2*0x%-8B\ " current char
169set statusline+=0x%-8B\ " current char
170set statusline+=%-14.(%l,%c%V%)\ %<%P " offset
171if filereadable(expand("$VIM/vimfiles/plugin/vimbuddy.vim"))
172    set statusline+=\ %{VimBuddy()} " vim buddy
173endif
174 
175"增强模式中的命令行自动完成操作
176set wildmenu
177 
178"执行 Vim 缺省提供的 .vimrc 文件的示例,包含了打开语法加亮显示等最常用的功能
179source $VIMRUNTIME/vimrc_example.vim
180 
181"缺省不产生备份文件
182set nobackup
183set noswapfile
184set nowritebackup
185"在输入括号时光标会短暂地跳到与之相匹配的括号处,不影响输入
186set showmatch
187"正确地处理中文字符的折行和拼接
188set formatoptions+=mM
189 
190"设定文件浏览器目录为当前目录
191set bsdir=buffer
192"自动切换当前目录为当前文件所在的目录
193set autochdir
194"自动重新加载外部修改内容
195"set autoread
196 
197"使PHP识别EOT字符串
198hi link phpheredoc string
199 
200"允许在有未保存的修改时切换缓冲区
201set hidden
202 
203"进入当前编辑的文件的目录
204autocmd BufEnter * exec "cd %:p:h"
205 
206"保存文件的格式顺序
207set fileformats=dos,unix
208 
209"配色(更多的配色见colors目录和http://www.cs.cmu.edu/~maverick/VimColorSchemeTest/index-c.html)
210"colorscheme peacock_light
211colorscheme peacock_desert
212 
213"启动后最大化
214au GUIEnter * simalt ~x
215 
216"置粘贴模式,这样粘贴过来的程序代码就不会错位了。
217"set paste
218 
219"记录上次关闭的文件及状态
220set viminfo='10,\"100,:20,%,n$VIMRUNTIME/_viminfo
221au 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:
226"http://cvs.php.net/viewvc.cgi/phpdoc/funclist.txt
227"set dictionary+=$VIM\vimfiles\syntax\function.txt
228au FileType php setlocal dictionary+=$VIM\vimfiles\syntax\function.txt
229 
230if !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            \})
238endif
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 
249function! ClosePair(char)
250  if getline('.')[col('.') - 1] == a:char
251    return "\<Right>"
252    else
253    return a:char
254  endif
255endf
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插件)
264let g:NERDChristmasTree = 1              "色彩显示
265let g:NERDTreeShowHidden = 1             "显示隐藏文件
266let g:NERDTreeWinPos = 'left'            "窗口显示位置
267let g:NERDTreeHighlightCursorline = 0    "高亮当前行
268nmap <C-F4>  :NERDTree<CR>
269 
270let g:SuperTabRetainCompletionType = 2
271let g:SuperTabDefaultCompletionType = "<C-X><C-O>"
272 
273"平台判断
274function! 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
282endfunction
283 
284"F8单独切换打开taglist(taglist插件)
285if GetSystem() == "windows"
286let g:Tlist_Ctags_Cmd = $VIMRUNTIME.'\ctags'
287else
288    let g:Tlist_Ctags_Cmd = '/usr/bin/ctags'
289endif
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文件
299set tags=tags;
300set autochdir
301 
302"Ctrl + F12删除&&更新tags文件
303function! 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
309endfunction
310nmap <C-F12> :call DeleteTagsFile()<CR>
311"退出VIM之前删除tags文件
312"au VimLeavePre * call DeleteTagsFile()
313 
314""""""""""""""""""""""""""""""
315" lookupfile setting
316""""""""""""""""""""""""""""""
317let g:LookupFile_MinPatLength = 2               "最少输入2个字符才开始查找
318let g:LookupFile_PreserveLastPattern = 0        "不保存上次查找的字符串
319let g:LookupFile_PreservePatternHistory = 1     "保存查找历史
320let g:LookupFile_AlwaysAcceptFirst = 1          "回车打开第一个匹配项目
321let g:LookupFile_AllowNewFiles = 0              "不允许创建不存在的文件
322if filereadable("./filenametags")                "设置tag文件的名字
323let g:LookupFile_TagExpr = '"./filenametags"'
324endif
325 
326"映射LookupFile为,lk
327nmap <silent> <leader>lk :LUTags<cr>
328"映射LUBufs为,ll
329nmap <silent> <leader>ll :LUBufs<cr>
330"映射LUWalk为,lw
331nmap <silent> <leader>lw :LUWalk<cr>
332"call pathogen#infect()
333let g:indent_guides_guide_size=1
334set modelines=20
335set confirm
336"set cscopetag
337Bundle 'DBGPavim'
338Bundle 'Tagbar'
339Bundle 'buffet.vim'
340let g:tagbar_ctags_bin = 'ctags'
341let g:tagbar_width = 30
342nmap <C-F5> :TagbarToggle<CR>
343nmap <C-F6> :Bufferlist<CR>
344set complete=t
345set display=lastline</pre><br>

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

点击查看原图

酱紫就大功告成了.

0 0