本文主要介绍了php工程师配置vim的详细过程,既有vim的配置效果图,还分享了vim配置的代码,感兴趣的小伙伴们可以参考一下。希望对大家有所帮助。
关于我的vim配置
经常在服务器上写代码,一个朋友提供了关于他的vim配置,在此分享给大家。
界面效果图:
.vimrc
内容如下
"=========================================================================
set nocompatible " be improved, required
filetype off " required
" git clone https://github.com/gmarik/vundle.vim.git ~/.vim/bundle/vundle.vim
" set the runtime path to include vundle and initialize
set rtp+=~/.vim/bundle/vundle.vim
call vundle#begin()
" let vundle manage vundle, required
plugin 'gmarik/vundle.vim'
" plugin on github repo
plugin 'shawncplus/phpcomplete.vim'
plugin 'scrooloose/nerdtree'
plugin 'kien/ctrlp.vim'
plugin 'bling/vim-airline'
plugin 'scrooloose/syntastic'
plugin 'vim-scripts/doxygentoolkit.vim'
plugin 'scrooloose/nerdcommenter'
plugin 'marcweber/vim-addon-mw-utils'
plugin 'tomtom/tlib_vim'
plugin 'garbas/vim-snipmate'
" optional:
plugin 'honza/vim-snippets'
" plugin from http://vim-scripts.org/vim/scripts.html
plugin 'vim-scripts/bufexplorer.zip'
plugin 'vim-scripts/cscope.vim'
plugin 'vim-scripts/taglist.vim'
" plugin 'vim-scripts/winmanager'
" plugin 'vim-scripts/project.tar.gz'
call vundle#end()
" brief help
" :pluginlist - lists configured plugins
" :plugininstall - installs plugins; append `!` to update or just :pluginupdate
" :pluginsearch foo - searches for foo; append `!` to refresh local cache
" :pluginclean - confirms removal of unused plugins; append `!` to auto-approve removal
filetype plugin on " required
syntax on " 自动语法高亮
set number " 显示行号
set cursorline " 突出显示当前行
" set ruler " 打开状态栏标尺
set shiftwidth=4 " 设定 << 和 >> 命令移动时的宽度为 4
set tabstop=4 expandtab " 设定 tab 长度为 4 个空格
set nobackup " 覆盖文件时不备份
" set autochdir " 自动切换当前目录为当前文件所在的目录
set backupcopy=yes " 设置备份时的行为为覆盖
set ignorecase smartcase " 搜索时忽略大小写,但在有一个或以上大写字母时仍保持对大小写敏感
set nowrapscan " 禁止在搜索到文件两端时重新搜索
" set incsearch " 输入搜索内容时就显示搜索结果
set hlsearch " 搜索时高亮显示被找到的文本
set noerrorbells " 关闭错误信息响铃
set novisualbell " 关闭使用可视响铃代替呼叫
set t_vb= " 置空错误铃声的终端代码
set magic " 设置魔术
set hidden " 允许在有未保存的修改时切换缓冲区,此时的修改由 vim 负责保存
set guioptions-=t " 隐藏工具栏
set guioptions-=m " 隐藏菜单栏
set smartindent " 开启新行时使用智能自动缩进
set backspace=indent,eol,start " 不设定在插入状态无法用退格键和 delete 键删除回车符
set cmdheight=1 " 设定命令行的行数为 1
set laststatus=2 " 显示状态栏 (默认值为 1, 无法显示状态栏)
set statusline=\ %<%f[%1*%m%*%n%r%h]%=\ %y\ %0(%{&fileformat}\ %{&encoding}\ %c:%l/%l%)\ " 设置在状态行显示的信息
set errorformat=%m\ in\ %f\ on\ line\ %l
set autoindent
set softtabstop=4 " 使得按退格键时可以一次删掉 4 个空格
colorscheme molokai
set t_co=256
"-----------------------------------------------------------------
" 获取当前系统类型
"------------------------------------------------------------------
function! mysys()
if has("win16") || has("win32") || has("win64") || has("win95")
return "windows"
elseif has("unix")
return "linux"
endif
endfunction
" 用户目录变量$vimfiles
if mysys() == "windows"
let $vimfiles = $vim.'/vimfiles'
set backupdir=d://vim/tmp
elseif mysys() == "linux"
let $vimfiles = $home.'/.vim'
set backupdir=/tmp
endif
" 设置字体 以及中文支持
if has("win32")
set guifont=inconsolata:h12:cansi
endif
" 配置多语言环境
if has("multi_byte")
" utf-8 编码
set encoding=utf-8
set termencoding=utf-8
set formatoptions+=mm
set fencs=utf-8,gbk
if v:lang =~? '^\(zh\)\|\(ja\)\|\(ko\)'
set ambiwidth=double
endif
if has("win32")
source $vimruntime/delmenu.vim
source $vimruntime/menu.vim
language messages zh_cn.utf-8
endif
else
echoerr "sorry, this version of (g)vim was not compiled with +multi_byte"
endif
" 光标到上方窗口,需要<c-w><c-w>k,非常麻烦,现在重映射为<c-k>
nnoremap <c-h> <c-w>h
nnoremap <c-j> <c-w>j
nnoremap <c-k> <c-w>k
nnoremap <c-l> <c-w>l
"一些不错的映射转换语法(如果在一个文件中混合了不同语言时有用)
nnoremap <leader>1 :set filetype=xhtml<cr>
nnoremap <leader>2 :set filetype=css<cr>
nnoremap <leader>3 :set filetype=javascript<cr>
nnoremap <leader>4 :set filetype=php<cr>
"-----------------------------------------------------------------
" 折叠配置
"
" manual 手工定义折叠
" indent 更多的缩进表示更高级别的折叠
" expr 用表达式来定义折叠
" syntax 用语法高亮来定义折叠
" diff 对没有更改的文本进行折叠
" marker 对文中的标志折叠
"------------------------------------------------------------------
set foldenable
set foldmethod=manual
set foldlevel=100 " 启动vim时不要自动折叠代码
set foldcolumn=0 " 设置折叠栏宽度
" python 文件的一般设置,比如不要 tab 等
" autocmd filetype python set tabstop=4 shiftwidth=4 expandtab
" autocmd filetype python map <f12> :!python %<cr>
" 设置数据字典 ~/.vim/dict/文件的路径
set complete-=k complete+=k
" autocmd filetype javascript set dictionary=$vimfiles/dict/javascript.dict
" autocmd filetype css set dictionary=$vimfiles/dict/css.dict
au filetype php setlocal dict+=$vimfiles/dict/php.dict
"-----------------------------------------------------------------
" plugin - winmanager 配置 (弃用,很多小bug)
"-----------------------------------------------------------------
" let g:winmanagerwindowlayout="nerdtree,taglist"
" let g:winmanagerwidth = 35
" let g:nerdtree_title="[nerdtree]"
"
" nmap <silent> <c-m> :if iswinmanagervisible() <bar> wmtoggle<cr> <bar> else <bar> wmtoggle<cr>:q<cr> endif <cr>
" " nmap <c-m> :wmtoggle<cr>
"
" function! nerdtree_start()
" exec 'nerdtree'
" endfunction
"
" function! nerdtree_isvalid()
" return 1
" endfunction
"-----------------------------------------------------------------
" plugin - doxygen toolkit 配置
"-----------------------------------------------------------------
let g:doxygentoolkit_brieftag_pre="@brief "
let g:doxygentoolkit_paramtag_pre="@param "
let g:doxygentoolkit_returntag="@return "
let g:doxygentoolkit_authorname="***"
let g:doxygentoolkit_brieftag_funcname="no"
let g:doxygen_enhanced_color=1
map fg : dox<cr>
map ffg : doxauthor<cr>
"-----------------------------------------------------------------
" plugin - nerdtree 配置
"-----------------------------------------------------------------
let nerdtreewinpos="left"
let nerdtreewinsize=30
" let nerdtreechdirmode=1 " 改变tree目录的同时改变工程的目录
nnoremap <silent><f6> :nerdtreetoggle<cr>
"-----------------------------------------------------------------
" plugin - ctags程序
"-----------------------------------------------------------------
if mysys() == "windows"
let tlist_ctags_cmd = '"'.$vimruntime.'/ctags.exe"'
elseif mysys() == "linux"
let tlist_ctags_cmd = '/usr/bin/ctags'
endif
set tags=~/acl/tags;
nnoremap <silent><f8> :!ctags -r --exclude=*.js --c++-kinds=+p --fields=+ias --extra=+q .<cr>
"-----------------------------------------------------------------
" plugin - taglist.vim
"-----------------------------------------------------------------
let tlist_show_one_file = 1 " 不同时显示多个文件的tag,只显示当前文件的
let tlist_exit_onlywindow = 1 " 如果taglist窗口是最后一个窗口,则退出vim
let tlist_use_right_window = 1 " 在右侧窗口中显示taglist窗口
let tlist_file_fold_auto_close=1 " 自动折叠当前非编辑文件的方法列表
let tlist_auto_open = 0
let tlist_auto_update = 1
let tlist_hightlight_tag_on_bufenter = 1
let tlist_enable_fold_column = 0
let tlist_compact_format = 1
" let tlist_display_prototype = 0
nnoremap <silent><f7> :tlisttoggle<cr>
"-----------------------------------------------------------------
" plugin - cscope设置
"-----------------------------------------------------------------
set cscopequickfix=s-,c-,d-,i-,t-,e-
if has("cscope")
set csprg=/usr/bin/cscope
set csto=1
set cst
set nocsverb
" add any database in current directory
" if filereadable("cscope.out")
" cs add cscope.out
" endif
" set csverb
" endif
nmap <c-@>s :cs find s <c-r>=expand("<cword>")<cr><cr>
nmap <c-@>g :cs find g <c-r>=expand("<cword>")<cr><cr>
nmap <c-@>c :cs find c <c-r>=expand("<cword>")<cr><cr>
nmap <c-@>t :cs find t <c-r>=expand("<cword>")<cr><cr>
nmap <c-@>e :cs find e <c-r>=expand("<cword>")<cr><cr>
nmap <c-@>f :cs find f <c-r>=expand("<cfile>")<cr><cr>
nmap <c-@>i :cs find i <c-r>=expand("<cfile>")<cr><cr>
nmap <c-@>d :cs find d <c-r>=expand("<cword>")<cr><cr>
endif
"-----------------------------------------------------------------
" plugin - project.vim 组织项目列表
" \c 递归读取子目录 \c 读取当前文件
" \l (列出所有当前层文件)\l(递归),按任何键停止
" \w (关闭当前层文件)\w(递归)
" \g (在项目当前层文件搜索)\g(递归)
" \r 关闭子文件夹并刷新当前文件夹下文件,\r递归打开文件夹并刷新所有文件
" \s 关闭文件夹并创建,\s递归打开文件夹并创建
" \s 将文件在水平打开多个窗口显示,打开或关闭文件夹列表
" \o 将文件在一个窗口打开,打开或关闭文件夹列表
" \v 在右窗口显示指针停留在project窗口的文件内容
" \i 显示文件或文件夹的设置参数,如filter="*"
" \i 显示文件或文件夹的决对路径和参数
" \1 - \9,\f1-\f9,\f1-\f9执行指定命令,\0查询1-9命令,\f0查询f1-f9,f1-f9命令
" <space>空格扩大project窗口的宽度,恢复宽度
"-----------------------------------------------------------------
" let proj_window_width=24
" let proj_window_increment=12
" let loaded_project = 1 " 停用插架
" let proj_flags="imstcg" " 自动隐藏project列表
" nnoremap <silent><f5> :project<cr> " f5 打开project窗口
"-----------------------------------------------------------------
" plugin - nerd_commenter.vim 注释代码用的,
" [count],cc 光标以下count行逐行添加注释(7,cc)
" [count],cu 光标以下count行逐行取消注释(7,cu)
" [count],cm 光标以下count行尝试添加块注释(7,cm)
" ,ca 在行尾插入 /* */,并且进入插入模式。 这个命令方便写注释。
" 注:count参数可选,无则默认为选中行或当前行
"-----------------------------------------------------------------
let nerdspacedelims=1 " 让注释符与语句之间留一个空格
let nerdcompactsexycoms=1 " 多行注释时样子更好看
"-----------------------------------------------------------------
" plugin - ctrlp 设置
"-----------------------------------------------------------------
nnoremap <silent> <c-p> :clearallctrlpcache<cr>\|:ctrlp<cr>
使用步骤:
1、下载插件管理器
~/.vim/bundle/vundle.vim
2、安装插件
打开一个文件
vim ~/.vimrc
进入命令执行安装
:bundleinstall
3、上传php自动实例字典及本色方案,解压至 .vim 目录下
相关推荐:
vim编辑器中全局替换命令的用法
vim 常用配置-让vim更好用
linux中vim 文书编辑器的实例详解
以上就是详解配置vim使其更利于php开发的详细内容。