VIM as a PHP IDE

UPDATE:  I'm using Emacs since some months and consider it superior to VIM for most use cases after using VIM for 4 years. (And I also came to hate PHP by the way.)

Today I read an article from Matthew Weier O'Phinney on Planet-PHP about  Programming PHP with VIM . Since he want's to continue his series and I wrote a similiar text these days, I thought to post the text I wrote so far.

Maybe we can continue together to write a nice teaser to for PHP with VIM. It would be fine, to have one place (vim.org, php.net/docs ?) to collect all those nice helper scripts and plugins. The main benefit could be, that all the scripts can be installed together without overlapping key mappings.

So much for now, since I'm with my family to celebrate easter. Happy Easter to everybody celebrating it today!

VIM as an IDE for PHP


Templates

TODO


Codesniffer integration

Codesniffer is a tool to check PHP code against a Coding standard. By integrating it into vim you can get the list of violations in a separate error window. The errow window allows jumping to each error in the source code, even if the line numbers have changed.

See help quickfix in the vim help.

phpcs.png

Put the following code in $VIMHOME/plugin/phpcs.vim:

function! RunPhpcs()
    let l:filename=@%
    let l:phpcs_output=system('phpcs --report=csv --standard=YMC '.l:filename)
"    echo l:phpcs_output
    let l:phpcs_list=split(l:phpcs_output, "\n")
    unlet l:phpcs_list[0]
    cexpr l:phpcs_list
    cwindow
endfunction

set errorformat+=\"%f\"\\,%l\\,%c\\,%t%*[a-zA-Z]\\,\"%m\"
command! Phpcs execute RunPhpcs()

Now you can run a Codesniff for the current file via

:Phpcs


Including Manuals

manpageview.png

Install the ManPageView script from Charles Campbell. It gives you access to the PHP manual, Perl manual and to man and info pages. The script could also be extended and I'd love to use it for Javascript and HTML, too. Make sure to take the most recent version, eventually from Campbell's homepage, since it may include bugfixes not yet uploaded to vimscripts.org.

You also need to install the links text browser, which is used to grap the online PHP manual:

apt-get install links

I took links, but elinks or links2 may work too.

After installation you simply press C-K on top of a keyword and the corresponding manual page will be opened in a separate window.


Autocompletition

Vim helps you to complete identifiers:

autocomplete.png

The first proposed item beginning with auto is an PHP function. Vim can autocomplete with different language dictionaries depending on the filetype. Thus it won't propose you any PYTHON function while you're editing a PHP file.

The second item is a word from another file I'm editing in the same Vim session. Thus you can easily complete Variablenames or Functionnames from other opened files.

Vim tells you also where it got the term from. Since the last item is from the same file, there's no filename written after the word.


PDV (phpDocumentor for Vim)

You do document your code with proper inline comments, do you? To make this task easier, Tobias Schlitt wrote a VIM plugin which automatically lookup some characteristics of the item you want to document and creates a Docblock sceleton for you:

pdv.png

@todo


Tag Browsing with cscope (Identifier lookup)

Just like in a big IDE like eclipse, you can easily jump to the definitions of functions and classes. Vim integrates cscope for the job (apt-get install cscope).

cscope.png

Build the taglist

Vim needs an index file for all identifiers. This file is build with cscope. First we create the file cscope.files which tells cscope which file to scan. In our case this are all files called *.php.

The -b option tells cscope to use the list from cscope.files:

cd project_dir
find . -name '*.php' > ./cscope.files
cscope -b
rm ./cscope.files

The shell commands from above left a file cscope.out in project_dir. Now we tell vim to use the generated tagfile:

cscope add project_dir/cscope.out project_dir

Note that you have to add the project_dir as the second argument to cscope add!



Taglist Window

Every IDE gives you an overview of all functions in a class, right?

taglist.png

Install exuberant-ctags ( >= Version 5.7 ) and the taglist vim plugin. On debian you go with:

apt-get install exuberant-ctags

vim-addons install taglist

Note

The 5.7 version of exuberant-ctags still has problems to parse PHP properly. It can not distinguis between the word "function" in a comment and a real function decleration. Therefore I still use a patched version of exuberant-ctags version 5.6.



Debug with xdebug

What's an IDE without a Debugger?

xdebug.png

You can find the most up to date link to the vim-xdebug plugin at the remote section of xdebug.org.

转载于:https://my.oschina.net/zhangdapeng89/blog/56599

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值