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.

  • 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

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=

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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