VIM 7.3.46
我定义了一个自定义语法文件,以使我的笔记更具可读性。
我想定义一个范围,该范围将在某些边界字符内应用现有语法文件(例如 php、javascript 或其他)的语法高亮显示。
例如,
Notes.txt
Notes would be here, blah blah...
More notes, then a javascript code block with proper js highlighting below this:
**jsbegin**
$('#jquerystuff').change(function(){
var example = $(this).val();
alert(example);
});
**jsend**
因此,我正在寻找类似这样的内容放入 vim 语法文件中:
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
但它只能将 JavaScript 突出显示应用于定义范围内的文本:
答案1
所需的行如下:
" 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