Vim自定义语法突出显示,包括指定范围内的其他语言语法


4

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突出显示:

Answers:


2

所需的行如下:

" 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

我认为我= s-1意味着高亮区域在jsend之前。那我可以用start=+\*\*jsbegin\*\*+ms=e+1吗?我尝试过但jsbegin仍然在JavaScript语法中突出显示。
Gqqnbig

@LoveRight你有没有解决过这个问题?我有同样的问题。
Azsgy
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.