2

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.

1 Answer 1

1

Use containedin=ALL:

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

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

Unfortunately this does not work if you add a second selector. E.g., .my-css { <?php echo 'my-php'; ?> } .my-css2 { <?php echo 'my-php2'; ?> }
Very strange. Would you mind uploading your php and css vim files somewhere for me to use? I'm wondering if it's an issue with one of these that's causing the problem...
Nevermind, looks like the css/php syntax files were the problem. Once I updated them all is working :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.