Different background color for multiple filetypes in vim

htmlPHPpluginsvim

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.

Best 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

Related Question