Many people are aware of the power of PHP heredocs, in that they allow variable expansion without the escape-hell of " and ' quotes having significance. The only downsides are the strictness of the
EOF marker locations and that constants cannot be used in heredocs.
I always used to be bothered by the fact that my code in heredocs was all-black, and not highlighted at all. I now realise that this is due to the fact that to get the highlighting you want, you need to choose your markers correctly. See
this comment for details. No more drab
EOF. I can assure you that the syntax highlighting allows for longer markers, like
HTMLform and so on.
So this method works for HTML, JavaScript and SQL. Great. But what if you, like me, create "dynamic stylesheets"? Here's an example:
<?php{FNAMEL}">header("Content-type: text/css");
{FNAMEL}">header("Cache-Control: must-revalidate");
//definitions$maintextcolour =
"#200";
$headingcolour =
"#622";
$bodyhighlight =
"#733";
$linkcolour =
"#755";
$linkhovercolour =
"#988";
{FNAMEL}">echo <<<CSS
body
{ color:
$maintextcolor;
}...etc...
CSS;
?>
You will notice that the "syntax highlighting in heredocs" won't work. In order to turn this on, we need to edit the php.vim file, which on my system (Ubuntu Hardy with vim7) is found at /usr/share/vim/vim71/syntax/php.vim
Edit that file and look for the heredoc lines. You'll see them like this (around line 375):
" HereDoc
if version >= 600
syn case match
syn region phpHereDoc matchgroup=Delimiter start="\(<<<\)@<=\z(\I\i*\)$" end="^\z1\(;\=$\)@=" contained contains=phpIdentifier,phpIdentifierSimply,phpIdentifierComplex,phpSpecialChar,phpMethodsVar keepend extend
" including HTML,JavaScript,SQL even if not enabled via options
syn region phpHereDoc matchgroup=Delimiter start="\(<<<\)@<=\z(\(\I\i*\)\=\(html\)\c\(\i*\)\)$" end="^\z1\(;\=$\)@=" contained contains=@htmlTop,phpIdentifier,phpIdentifierSimply,phpIdentifierComplex,phpSpecialChar,phpMethodsVar keepend extend
syn region phpHereDoc matchgroup=Delimiter start="\(<<<\)@<=\z(\(\I\i*\)\=\(sql\)\c\(\i*\)\)$" end="^\z1\(;\=$\)@=" contained contains=@sqlTop,phpIdentifier,phpIdentifierSimply,phpIdentifierComplex,phpSpecialChar,phpMethodsVar keepend extend
syn region phpHereDoc matchgroup=Delimiter start="\(<<<\)@<=\z(\(\I\i*\)\=\(javascript\)\c\(\i*\)\)$" end="^\z1\(;\=$\)@=" contained contains=@htmlJavascript,phpIdentifierSimply,phpIdentifier,phpIdentifierComplex,phpSpecialChar,phpMethodsVar keepend extend
syn region phpHereDoc matchgroup=Delimiter start="\(<<<\)@<=\z(\(\I\i*\)\=\(css\)\c\(\i*\)\)$" end="^\z1\(;\=$\)@=" contained contains=@cssTop keepend extend
syn case ignore
endif
You might note a line in my code above that is not in yours. I have added the CSS line.
The story's not over: the CSS syntax file needs to be included into the PHP one. Place this line near the top of the file with the others like it. and before the "syn case match" line):
syn include @cssTop syntax/css.vim
Post a comment if you need any help. This should work for vim6 and up, but the above line might need changing for pre-version 6 VIMs. Those of you who haven't upgraded (or can't) should try:
syn include @cssTop <sfile>:p:h/css.vim
Good luck!