Search code examples
vimsyntax-highlightingmacvimvim-syntax-highlighting

Combining multiple syntaxes in MacVim


I'm trying to create a custom syntax highlighter for MacVim that uses a combination of CSS and PHP, where CSS is static selectors, and sometimes there will be embedded PHP code (very similar to HTML+PHP).

Here is my syntax file:

"Import CSS first
runtime! syntax/css.vim
unlet b:current_syntax

" Use PHP any time there is <? ?>
syn include @syntaxPHP syntax/php.vim
syn region regionPHP start="<?" end="?>" contains=@syntaxPHP

When I open the following:

.my-css {
    <?php echo 'my-php'; ?>
}

Only the php part is colored, the css is not.


Solution

  • Use containedin=ALL:

    syn region regionPHP start="<?" end="?>" containedin=ALL contains=@syntaxPHP
    

    enter image description here