0

I have been coding in PHP lately, which is weakly typed so integers are added with += but strings are concatenated with .=. That means that I wind up using += where I shouldn't and PHP actually then converts my strings to integers!

Is there any way to highlight +=, which I hardly ever use, with a background or something else very distinctive?

Thanks.

1

1 Answer 1

2

Here is one way to do it:

Create a php.vim in your after/syntax directory like this:

scriptencoding utf-8

setlocal nolist

syn match phpPlusEq '+='

hi link phpPlusEq       Error

" vim: ts=8 sw=2

Next time you edit a php file, the += should be highlighted as error.

10
  • Thank you. I have created the file ~/.vim/after/syntax/php.vim and populated it with the content that you mention. However, += is not highlighted in file ~/text.php. This is on Kubuntu Linux 11.10, VIM 7.3. Any idea why? I do see that this is the right solution, though, so I am already marking it as accepted even though it is not working for me right now.
    – dotancohen
    May 1, 2012 at 10:16
  • 1
    @dotancohen. Do :scriptnames in vim and you should see ~/.vim/after/syntax/php.vim towards the end of the list.
    – lang2
    May 2, 2012 at 4:40
  • Thanks. It looks like I have the text in the right place but even so, that file is not on the list. Any reasons why that might be?
    – dotancohen
    May 2, 2012 at 8:20
  • I don't really know but I'm suspecting kunbuntu. Can you do :set rtp? and check your run time path?
    – lang2
    May 2, 2012 at 10:05
  • Thanks. ~/.vim/after/ is in the run time path, but ~/.vim/after/syntax is not. Note that ~/.vim/after/plugin is not on the list either, but my ~/.vim/after/plugin/matchparen.vim file works as expected. Strange.
    – dotancohen
    May 2, 2012 at 10:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .