Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is it possible to have different background colors in vim (ie. one light, one dark) when dealing with files with multiple filetypes (ie. :set ft=html.php)? In PHP code with HTML embedded, it can be difficult to see one single PHP statement amongst dozens of HTML lines, see below. I'll settle for anything, be it different bg color, a marker in the margin, a second left margin (one vim plugin does this for marks), maybe highlighting the <?php tag for example (although that's less than ideal)

PHP in HTML Code

EDIT: I don't think this is possible at the syntax level as the syntax appears to use a limited number of elements (String, Function, Identifier...). This is no doubt to allow for the easy integration with colorschemes. SyntaxAttr is a good plugin to demonstrate this. Put it over any part of the code and it will tell you what syntax group it belongs to.

share|improve this question
    
Possibly you could use the same solution as in this post stackoverflow.com/questions/4167425/… where they create a custom color scheme which highlights any string starting with sql_. –  David Mårtensson Mar 20 '12 at 17:41
1  
I'll see if I can get it to detect regions between ?> and <? as non PHP. –  puk Mar 20 '12 at 18:45
add comment

migrated from stackoverflow.com Mar 27 '12 at 15:34

This question came from our site for professional and enthusiast programmers.

1 Answer

Another potential solution is to customize your favorite colorscheme file to check for the setting of 'background'. Many set the 'background' setting one way or the other, but it can be checked to change what the highlighting colors would be.

Example colorscheme


" Search
if &background=="dark"
  hi IncSearch    gui=UNDERLINE guifg= ctermfg=
else " background is light
  hi IncSearch    gui=UNDERLINE guifg= ctermfg=
fi

share|improve this answer
    
Is there a way to check the language of a word/character? ie if it is HTML v PHP? –  puk Apr 4 '12 at 18:07
    
Sort of depends. You can check the hightlighting type for a particular word. And if it is distinguishable between HTML and PHP, you would know. But I think that is the best you'll get without a lot of extra work. Use something like the following to get the highlight type: :echo synIDattr(synID(line("."),col("."),1),"name") –  pottsdl Apr 4 '12 at 18:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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