4

I followed some tutorials to debug and lint php code through VIM.

Here is my piece of PHP code to test

<?php echo "test" echo "test2";?>

The following code worked for me:

:autocmd FileType php noremap <C-L> :!$HOME/bin/php -l %<CR>

It tells me that there is a syntax error. Problem is that i want to use the quickfix console. So, here is the code:

set makeprg="php -l %"
nmap <F9>:make<ENTER>:copen<ENTER><CTRL>L

F9 opens the quickfix window, but detects no syntax error. (I save my php document before with :w)

Thanks for your time !

2
  • What happens if you simply call :make and then use :copen?
    – Xavier T.
    Aug 25, 2011 at 16:15
  • @Xavier T. : It works great and there is no bug like I mentionned in my comment on the Peter Rincker's answer. Now, question is, why your solution doesn"t work with key mapping... Thanks !
    – Matthieu
    Aug 26, 2011 at 20:28

1 Answer 1

3

The problem i see is using " w/ :set. I suggest the following:

:set makeprg=php\ -ln\ %
:set errorformat=%m\ in\ %f\ on\ line\ %l
nnmap <f9> :sil! make<cr>:cwindow<cr>

To make this a bit more friendly with other file types I suggest you put the following in your ~/.vim/after/ftplugin/php.vim and making sure you use :setlocal and your mappings have <buffer> attribute like this:

:setlocal makeprg=php\ -ln\ %
:setlocal errorformat=%m\ in\ %f\ on\ line\ %l
nnmap <buffer> <f9> :sil! make<cr>:cwindow<cr>
6
  • Thanks! Somehow, It looks like to work but I think there is a little bug (maybe with my vimrc)... Some screenshots worth more than words: Before and After
    – Matthieu
    Aug 26, 2011 at 14:55
  • I tried your snippets on a fresh Ubuntu install and i have the same display bug. A part of the source code is erased when i trigger F9
    – Matthieu
    Aug 26, 2011 at 21:07
  • @Matthieu: I do not completely understand what the bug is. Could you clarify? Aug 27, 2011 at 13:12
  • 1
    @Matthieu: this is just a guess of what your bug is, try setting errorformat with :set errorformat=%m\ in\ %f\ on\ line\ %l,%-GErrors\ parsing\ %f,%-G Aug 27, 2011 at 13:31
  • Have you seen the pictures behind the links Before and After on my first comment ? Thing is that when i trigger F9, a part of my code is erased (Not in quickfix window but in my source code). Not erased from the file, because when i reopen it, nothing has changed. It looks like a "display" bug. Very weird...
    – Matthieu
    Aug 27, 2011 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.