Syntastic syntax checker for VIM

In an earlier post I explained how to make PHP syntax checking available in VIM. Recently I came across the Syntastic VIM plugin which offers a much better VIM integration as well as syntax checking for more than 60 languages. A nice feature of Syntastic is that you can chain several checkers. In the case of PHP you can chain the a regular PHP syntax check with the PHP_CodeSniffer style checker. This way you get warnings about syntax as well as style issues.

In case of an issue Syntastic will highlight the line where the issue occurred:
Syntastic error screen

I recommend to use the pathogen VIM plugin and keep all your VIM plugins in individual subdirectories of .vim/bundle. You can either clone or copy the Syntastic plugin there. Once the plugin is installed you can run the :SyntasticInfo command in any file and you will get list of the active checkers.

Syntastic info for filetype: php
Available checkers: php
Currently active checker(s): php

Syntastic automatically runs when saving the file and you can trigger a syntax check any time by executing :SyntasticCheck

If you want to enable style checks you need to install PHP_CodeSniffer. On my Ubuntu install (Ubuntu-Server 12.04 LTS) the packaged version of PHP_CodeSniffer is too dated to work with Syntastic so I went with installing the PEAR version.

root@ubuntu:~# pear install PHP_CodeSniffer

Then you need to add PHP_CodeSniffer to the checker list for PHP by adding these lines to your .vimrc:

let g:syntastic_php_checkers = ['php', 'phpcs']
let g:syntastic_php_phpcs_args = "--standard=zend -n --report=csv"

You can configure various style standards. I went with the Zend standard. You can change the arguments to your needs. You can see a full list of the available arguments by running phpcs –help.

Syntastic syntax checker for VIM