created April 6, 2004 · complexity basic · author vid luther · version 6.0
Ever wanted to just check your php script to see if it had any syntax errors? Similar to perl -c?. You could always do it by doing php -l, with this little macro, you can do it in your buffer.
Just add the following line in your vimrc, and whenever you want to test, press ctrl-b
map <C-B> :!php -l %<CR>
Comments
To improve on this great tip, here's how to check PHP syntax without having to save first:
map <C-B> :w !php -l<CR>
I would prefer to invoke the command via :make.
:set makeprg=php\ -l\ %
If you also set 'autowrite' to true the file is automatically written when calling :make
See also:
Setting this:
autocmd QuickFixCmdPre make w
will auto-save the buffer when :make is invoked. (useful if you don't want autowrite on for other commands)
Having this will make Vim jump to the first error occurred during compilation afterwards:
set errorformat=%m\ in\ %f\ on\ line\ %l
Well I'm using this to test php syntax pressing <C-P> in normal mode, if there are errors it automatically opens the error window (you should put the following code into a file that is sourced when editing a php file)
function! PHPsynCHK() let winnum =winnr() " get current window number silent make -l % cw " open the error window if it contains error " return to the window with cursor set on the line of the first error (if any) execute winnum . "wincmd w" endfunction :setl makeprg=php :set errorformat=%m\ in\ %f\ on\ line\ %l " Map <CTRL>-P to check the file for syntax :noremap <C-P> :call PHPsynCHK()<CR>