Different background color for multiple filetypes in vim

10

1

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.

puk

Posted 2012-03-14T13:36:05.287

Reputation: 607

Possibly you could use the same solution as in this post http://stackoverflow.com/questions/4167425/custom-syntax-highlighting-in-vim where they create a custom color scheme which highlights any string starting with sql_.

– None – 2012-03-20T17:41:16.203

1I'll see if I can get it to detect regions between ?> and <? as non PHP. – puk – 2012-03-20T18:45:16.377

Answers

1

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

pottsdl

Posted 2012-03-14T13:36:05.287

Reputation: 606

Is there a way to check the language of a word/character? ie if it is HTML v PHP? – puk – 2012-04-04T18:07:17.917

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 – 2012-04-04T18:47:58.363