VIM syntax highlighting of html nested in yaml

前端 未结 4 2091
臣服心动
臣服心动 2021-01-04 06:38

Given a yaml file that contains html, like this:

template        : |+ 
    
Hello, world

Is

4条回答
  •  鱼传尺愫
    2021-01-04 06:46

    check out my related question: Trouble using Vim's syn-include and syn-region to embed syntax highlighting. There I am trying to embed Python within TeX, but I think the solution might work for your case, too.

    I think you want to do something like this:

    let b:current_syntax = ''
    unlet b:current_syntax
    runtime! syntax/yaml.vim
    
    let b:current_syntax = ''
    unlet b:current_syntax
    syntax include @YaML syntax/yaml.vim
    
    let b:current_syntax = ''
    unlet b:current_syntax
    syntax include @HTML syntax/html.vim
    syntax region htmlEmbedded matchgroup=Snip start='#{{{html' end='#html}}}' containedin=@YaML contains=@HTML
    
    hi link Snip SpecialComment
    let b:current_syntax = 'yaml.html'
    

    The block with the runtime! command might be unnecessary if your YaML is already highlighted.

提交回复
热议问题