Ubuntu 下 vim 开发Php 环境配置



利用ctrl+ww来进行两个窗口之间的切换。
按下F8键,就可以在左侧看到一个目录树了
F6 开启TlistToggle   没弄出效果
cp -a 路径 到路径
touch 建空文件
mkdir 建空文件夹
ctrl+alt+d 桌面
ctrl+alt +T 打开终端
输入 div>p#foo$*3>a 这样的缩写,然后按 ctrl + y + , 来展开(注意那个逗号),展开后它应该是这个样子的

在taglist窗口中,可以使用下面的快捷键:

<CR>       跳到光标下tag所定义的位置,用鼠标双击此tag功能也一样
o             在一个新打开的窗口中显示光标下tag
<Space>  显示光标下tag的原型定义
u             更新taglist窗口中的tag
s             更改排序方式,在按名字排序和按出现顺序排序间切换
x             taglist窗口放大和缩小,方便查看较长的tag
+             打开一个折叠,同zo
-             将tag折叠起来,同zc
*             打开所有的折叠,同zR
=            将所有tag折叠起来,同zM
[[            跳到前一个文件
]]            跳到后一个文件
q            关闭taglist窗口
在vimrc中加下面设置可以按F6打开关闭taglist
"函数和变量列表
map <F6> :TlistToggle<CR>

IDE左侧是目录导航,中间是编辑区域,而右侧则是方法列表,用于在已经打开的文件中快速跳转。在编辑区

域按下CTRL+X键,还会显示已打开文件的列表。


重启vim后,按下F8键,就可以在左侧看到一个目录树了。在目录树窗口中按下?键可以查看详细的帮助信息

最常用的操作键有:

 按键 作用
 C(大写C键) 将光标所在目录设置为根目录
 u(小写u键) 转到上一级目录
 o(小写o键,不是“零”) 展开(或折叠)光标所在目录的子目录。如果光标所在位置是一个文件,则在编辑窗口中打开该文件

此外在目录树窗口中输入目录:Bookmark 收藏名还可以将光标所在目录添加到收藏夹中。下次使

:BookmarkToRoot 收藏名可以直接转到该目录,并且以该目录作为根目录。更多命令可以参考NERDTree的

帮助文档。



=====整理自己的步骤============
安装vim   sudo apt-get install vim  sudo apt-get install gvim
或者:     安装vim:更新下源,sudo apt-get update ,然后在下载安装vim,sudo apt-get install vim。   change

将其中的php.vim复制到$VIM\vimfiles\syntax目录中即可。$VIM根据不同系统不同,我的是ubuntu,执行

whereis vim :

root@Cyrec-desktop:/usr/share/vim/vimfiles# whereis vim
vim: /usr/bin/vim /usr/bin/vim.basic /etc/vim /usr/share/vim /usr/share/man/man1/vim.1.gz 可以找到vim安装

在/usr/share/vim中,下面的/usr/share/vim都用$VIM代替。

------------2--------------------------------------------------------
下载地址: http://www.vim.org/scripts/script.php?script_id=1571
下载文件:php.tar.gz 将其中的php.vim复制到$VIM\vimfiles\syntax目录中即可
-------------3----用NERDTree实现目录导航---------------------
下载地址: http://www.vim.org/scripts/script.php?script_id=1658
下载文件:NERD_tree.zip   解压缩到$VIM\vimfiles目录中。完成后,应该分别找到$VIM

\vimfiles\doc\NERD_tree.txt文件和$VIM\vimfiles\plugin\NERD_tree.vim文件。然后在vim中输入命令:helptags

$VIM\vimfiles\doc,将NERDTree的帮助文档添加到vim中。

最后在_vimrc添加如下内容:

” NERDTree

map <F8> :NERDTreeToggle<CR>

重启vim后,按下F8键,就可以在左侧看到一个目录树了。在目录树窗口中按下?键可以查看详细的帮助信息

最常用的操作键有:

-------------4---taglist可以 列出已打开文件中定义的类、函数、常量,甚至变量-------------
下载地址: http://www.vim.org/scripts/script.php?script_id=273
下载文件:taglist_45.zip
完整解压缩到$VIM\vimfiles目录,并且用:helptags $VIM\vimfiles\doc命令索引taglist插件的帮助文

档。taglist插件需要依赖ctags程序才能工作。目前常用的ctags版本是Exuberant Ctags。

sudo apt-get install ctags,然后whereis ctags,找到ctags: /usr/bin/ctags 这目录下的ctags。

将ctags复制到$VIM\vim72目录中即可。

最后在/etc/vim/vimrc添加下列内容,设置好taglist插件:

“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"

” => Plugin configuration

“”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"”"

” taglist

let Tlist_Auto_Highlight_Tag = 1

let Tlist_Auto_Open = 1

let Tlist_Auto_Update = 1

let Tlist_Close_On_Select = 0

let Tlist_Compact_Format = 0

let Tlist_Display_Prototype = 0

let Tlist_Display_Tag_Scope = 1

let Tlist_Enable_Fold_Column = 0

let Tlist_Exit_OnlyWindow = 0

let Tlist_File_Fold_Auto_Close = 0

let Tlist_GainFocus_On_ToggleOpen = 1

let Tlist_Hightlight_Tag_On_BufEnter = 1

let Tlist_Inc_Winwidth = 0


-----5--用AutoComplPop实现代码自动提示----------------

点击下面网址,进去下载autocomplpop插件

http://www.vim.org/scripts/script.php?script_id=1879

下载的是一个zip文件,解压后会有三个文件夹,分别是autoload,doc,plugin。到Vim的根目录下,找到名字

和这三个一样的文件夹。不同系统目录位置不同。我的fedora是/usr/share/vim/vimfiles

按照文件夹对应的把里面的acp.vim和其他的什么文件都copy过去。然后重启Vim。这时候可能会有错误提示

Error detected while processing /home/carlos/.vim/plugin/acp.vim:
line 13:
***** L9 library must be installed! *****

这是插件放出的一个错误提示,查看plugin里的acp.vim可以看到。是缺少L9 library库。这个也是需要下载的。地址在下面

http://www.vim.org/scripts/script.php?script_id=3252

下载下来,它也是一个插件形式,以同样的方式copy到Vim目录下。

安装完后就可以了。

再就是这个插件默认是没有设置php自动补全的,可以设置一个PHP函数字典,让其根据字典的内容进行自动

补全。

这个是一个PHP字典:.
下载地址:http://svn.php.net/viewvc/phpdoc/doc-base/trunk/funclist.txt?view=log
编辑配置文件.vimrc,在文件后面加上下面的代码
au FileType php setlocal dict+=/etc/vim/php_funclist.txt
后面跟着的是字典的目录地址,根据自己的需求存放在一个地方就好。我是放到了/etc/vim/目录下。  php_funclist下载:php_funclist.tar.gz

再附加一些自动补全配置(加入到vimrc中):

php 中 一般是会在 "$", "->", "::" 后需要出现自动补全,在 .vimrc 中加入以下代码:

if !exists('g:AutoComplPop_Behavior')     let g:AutoComplPop_Behavior = {}     let g:AutoComplPop_Behavior['php'] = []     call add(g:AutoComplPop_Behavior['php'], {             \   'command'   : "\<C-x>\<C-o>",              \   'pattern'   : printf('\(->\|::\|\$\)\k\{%d,}$', 0),             \   'repeat'    : 0,             \}) endif

在 Vim 中实现括号自动补全:

:inoremap ( ()<ESC>i
:inoremap ) <c-r>=ClosePair(')')<CR>
:inoremap { {}<ESC>i
:inoremap } <c-r>=ClosePair('}')<CR>
:inoremap [ []<ESC>i
:inoremap ] <c-r>=ClosePair(']')<CR>
:inoremap < <><ESC>i
:inoremap > <c-r>=ClosePair('>')<CR>

function ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endf

这样,写代码的时候不再担心会丢掉右边的括号了,尤其是函数嵌套的时候。

------6---安装ZenCoding插件-------------

http://github.com/mattn/zencoding-vim下载压缩包,然后解压到vimfiles文件夹,和上面一样,将doc plugin

autoload三个文件夹放到相应文件夹下。然后在vim中输入helptags /etc/vim/doc 导入帮助文件.就OK了。

zencoing可以很方便的写html,一些常用命令:

输入 div>p#foo$*3>a 这样的缩写,然后按 ctrl + y + , 来展开(注意那个逗号),展开后它应该是这个样子的

 <div>       <p id="foo1">           <a href="http://want2.blog.163.com/blog/"></a>       </p>       <p id="foo2">           <a href="http://want2.blog.163.com/blog/"></a>       </p>       <p id="foo3">           <a href="http://want2.blog.163.com/blog/"></a>       </p>   </div> 
  • 多行缩写

输入如下:

test1 test2 test3 

然后进入行选择模式,选中这三行按 ctrl + y + ,,接着它会提示你要使用的tag名称,TAG: 输入 ‘ul>li* 会变成如下的样子

<ul>     <li>test1</li>     <li>test2</li>     <li>test3</li> </ul> 

如果是输入blockquote,那么会变成这样

  <blockquote>       test1       test2       test3   </blockquote> 
  • 跳转到下一个标签编辑位置

输入ctrl + y + n 进入插入模式

  • 跳转到上一个标签编辑位置

输入ctrl + y + N 进入插入模式

  • 更新标签中图片大小

假如有以下内容

<img src="http://want2.blog.163.com/blog/foo.png" /> 

光标移动到img标签上,按下ctrl + y + i 该插件会自动获取foo.png的大小并插入宽高属性 看起来像这个样子

<img src="http://want2.blog.163.com/blog/foo.png" width="32" height="48" /> 
  • 切换注释

如有以下段

<div>     hello world </div> 

光标移动到此段落,输入ctrl + y + /变成

<!-- <div>     hello world </div> --> 

再次输入则还原

  • 生成url连接

将光标移动到一个url上,如:

http://www.google.com/ 

输入ctrl + y + a 它会自动获取url页面的标题并生成一个连接

<a href="http://www.google.com/"></a> 

Zen Coding官方提供的速查手册(PDF):http://zen-coding.googlecode.com/files/ZenCodingCheatSheet.pdf

没用 pdf;

======要知道的是===============
用到了NERDtree,taglist,AutoComplPop,ZenCoding插件和一些配置
如果想一次配置,所有用户都能使用,那就修改 /etc/vim/vimrc,如果只想当前用户可以使用,则修改 ~/.vim



====最终=======================
在 /usr/share/vim/vimrci  为
" All system-wide defaults are set in $VIMRUNTIME/debian.vim (usually just
" /usr/share/vim/vimcurrent/debian.vim) and sourced by the call to :runtime
" you can find below.  If you wish to change any of those settings, you should
" do it in this file (/etc/vim/vimrc), since debian.vim will be overwritten
" everytime an upgrade of the vim packages is performed.  It is recommended to
" make changes after sourcing debian.vim since it alters the value of the
" 'compatible' option.

" This line should not be removed as it ensures that various options are
" properly set to work with the Vim-related packages available in Debian.
runtime! debian.vim

" Uncomment the next line to make Vim more Vi-compatible
" NOTE: debian.vim sets 'nocompatible'.  Setting 'compatible' changes numerous
" options, so any other options should be set AFTER setting 'compatible'.
"set compatible

" Vim5 and later versions support syntax highlighting. Uncommenting the next
" line enables syntax highlighting by default.
if has("syntax")
  syntax on
endif

" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
"set background=dark

" Uncomment the following to have Vim jump to the last position when
" reopening a file
"if has("autocmd")
"  au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
"endif

" Uncomment the following to have Vim load indentation rules and plugins
" according to the detected filetype.
"if has("autocmd")
"  filetype plugin indent on
"endif

" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
"set showcmd  " Show (partial) command in status line.
"set showmatch  " Show matching brackets.
"set ignorecase  " Do case insensitive matching
"set smartcase  " Do smart case matching
"set incsearch  " Incremental search
"set autowrite  " Automatically save before commands like :next and :make
"set hidden             " Hide buffers when they are abandoned
"set mouse=a  " Enable mouse usage (all modes)

" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
  source /etc/vim/vimrc.local
endif

"新配置
    au FileType php,c,java,javascript,html,htm,smarty call SetOption()
    function! SetOption()
      set expandtab    " 使用空格代替tab
      set shiftwidth=4 " 设定 <<  >> 命令移动时的宽度为 4
      set tabstop=4    " 用4个空格代替1个tab
      set sts=4        " 设置softtabstop  4,输入tab后就跳了4格.
      set cindent      " C语言方式缩进
      set smartindent  " 智能缩进
      set autoindent   " 自动缩进
      set smarttab     " 只在行首用tab,其他地方的tab都用空格代替
      set showmatch    " i在输入括号时光标会短暂地跳到与之相匹配的括号处
      " set fdm=indent " 代码折叠
      set lbr
      set tw=500
      set wrap         " 自动换行
    endfunction
 NERDTree

map <F8> :NERDTreeToggle<CR>
“=>Plugin configuration

“”"”""”""”""”""”""”""”""”""”""”""”""”""”""”""”""

” taglist

let Tlist_Auto_Highlight_Tag = 1

let Tlist_Auto_Open = 1

let Tlist_Auto_Update = 1

let Tlist_Close_On_Select = 0

let Tlist_Compact_Format = 0

let Tlist_Display_Prototype = 0

let Tlist_Display_Tag_Scope = 1

let Tlist_Enable_Fold_Column = 0

let Tlist_Exit_OnlyWindow = 0

let Tlist_File_Fold_Auto_Close = 0

let Tlist_GainFocus_On_ToggleOpen = 1

let Tlist_Hightlight_Tag_On_BufEnter = 1

let Tlist_Inc_Winwidth = 0


map <F6> :TlistToggle<CR>

au FileType php setlocal dict+=/etc/vim/php_funclist.txt

if !exists('g:AutoComplPop_Behavior')
    let g:AutoComplPop_Behavior = {}
    let g:AutoComplPop_Behavior['php'] = []
    call add(g:AutoComplPop_Behavior['php'], {
            \   'command'   : "\<C-x>\<C-o>", 
            \   'pattern'   : printf('\(->\|::\|\$\)\k\{%d,}$', 0),
            \   'repeat'    : 0,
            \})
endif

“在 Vim 中实现括号自动补全:

:inoremap ( ()<ESC>i
:inoremap ) <c-r>=ClosePair(')')<CR>
:inoremap { {}<ESC>i
:inoremap } <c-r>=ClosePair('}')<CR>
:inoremap [ []<ESC>i
:inoremap ] <c-r>=ClosePair(']')<CR>
:inoremap < <><ESC>i
:inoremap > <c-r>=ClosePair('>')<CR>

function ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endif

$ ls /usr/share/vim/vimfiles/
autoload  gvimrc           php_funclist.txt  syntax      vimrc   vimrc.tiny
doc       nerdtree_plugin  plugin            taglist_45  vimrc~


$ ls /usr/share/vim/
addons  ctags  gvimrc  registry  vim72  vim73  vimcurrent  vimfiles  vimrc  vimrc.tiny

$ ls ./autoload ./plugin ./doc
./autoload:
acp.vim  autoload  l9  l9.vim  zencoding.vim    //新添加了acp.vim  l9  l9.vim  zencoding.vim,其中l9是文件夹
./doc:
acp.jax  acp.txt  l9.jax  l9.txt  NERD_tree.txt  tags  zencoding.txt  //都是新添加的,tags忘记了
./plugin:
acp.vim  l9.vim  NERD_tree.vim  zencoding.vim  //都是新添加的

$ ls ./autoload/l9/
async.py  async.vim  quickfix.vim  tempbuffer.vim  tempvariables.vim

那个ctags复制vim单前目录下
在vim/vimfiles目录下有几个新文件夹:php_funclist.txt 和 nerdtree_plugin 和 syntax 和 taglist_45
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值