PHP Syntax error testing in VIM

Please see my article about the Syntastic Vim Plugin for a better way of syntax checking in VIM.

I find it really helpful to be able to test for syntax errors from within VIM. VIM offers this option via filetype plugins and the :make command. To enable this functionality 2 small config changes are necessary.


# Map the make command to CTRL+t 
map <C-T> :w<CR>:make <CR>


# Set the make command to execute the PHP syntax checker
set makeprg=php\ -l\ %
# Update error formatting
set errorformat=%m\ in\ %f\ on\ line\ %l

This will only change the make command for .php  files and keep other files unaffected.

Once you changed those 2 files you can hit CTRL+t and you will see if you have any syntax errors in your code:

PHP Parse error:  syntax error, unexpected ';' in test.php on line 3
Errors parsing test.php

Note: Executing the syntax test will save the file before testing.

I'm available for contracting work. Check out my LinkedIn profile and my portfolio page for an overview of my skills and experience. If you are interested in working with me please use the contact form to get in touch.

PHP Syntax error testing in VIM

Leave a Reply

Your email address will not be published. Required fields are marked *