Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
1  
    
Thanks, Daniel, I'm going through those posts now. – dotancohen May 2 '12 at 12:44
up vote 2 down vote accepted

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.

share|improve this answer
    
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 '12 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 '12 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 '12 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 '12 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 '12 at 10:17

You must log in to answer this question.

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