Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

VIM 7.3.46

I have a custom syntax file defined for making my notes more readable.

I want to define a range that will apply syntax highlighting from an existing syntax file (e.g. php, javascript or whatever) within certain boundary characters.

For example,

Notes would be here, blah blah...
More notes, then a javascript code block with proper js highlighting below this:

        var example = $(this).val();

So I'm looking for something like this to put in the vim syntax file:

so <sfile>:p:h/javascript.vim
so <sfile>:p:h/php.vim

syn region notesJS matchgroup=javascript start="**jsbegin**" end="**jsend**" contains=javascript
syn region notesPHP matchgroup=php start="**phpbegin**" end="**phpend**" contains=php

But it must only apply javascript highlighting to text within the defined range:

share|improve this question
up vote 2 down vote accepted

The required lines are as follows:

" Include PHP highlighting between **phpbegin** and **phpend** tags
syn include @notesPHP syntax/php.vim
syn region phpCustom start=+\*\*phpbegin\*\*+ keepend end=+\*\*phpend\*\*+ contains=@notesPHP

" Include JavaScript highlighting between **jsbegin** and **jsend** tags
syn include @notesJavaScript syntax/javascript.vim
syn region javaScriptCustom start=+\*\*jsbegin\*\*+ keepend end=+\*\*jsend\*\*+me=s-1 contains=@nJavaScript
share|improve this answer
I think me=s-1 means the highligh region is before jsend. Then can I use start=+\*\*jsbegin\*\*+ms=e+1 ? I tried it but jsbegin is still highlighted in JavaScript syntax. – LoveRight Jul 20 '15 at 23:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .