嵌套在 yaml 中的 html 的 VIM 语法高亮显示 [英] VIM syntax highlighting of html nested in yaml

查看:47
本文介绍了嵌套在 yaml 中的 html 的 VIM 语法高亮显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个包含 htmlyaml 文件,如下所示:

Given a yaml file that contains html, like this:

template        : |+ 
    <div>Hello, world</div>

是否可以在 Vim(7.3.087 版)中使用 html 语法突出显示来突出显示 html 部分?

Is it possible in Vim (version 7.3.087) to highlight the html portion with html syntax highlighting?

我发现了帖子 文件区域内的不同语法高亮,它似乎有我一直在寻找的概念,但我无法使用 yaml 让它按预期工作.我希望能够执行以下操作(如链接中所建议):

I found the post Different syntax highlighting within regions of a file, which seems to have exactly the concept I was looking for, but I cannot get it to work as expected with yaml. I'd expect to be able to do the following (as suggested in the link):

" .vimrc
" include the code from the above link
call TextEnableCodeSnip('html' ,'#{{{html' ,'#html}}}', 'SpecialComment')

然后将 yaml 设为例如:

 template        : |+  #{{{html
    <div>Hello, world</div>
 #html}}}

不幸的是,这并没有按预期工作,即 html 代码仍然完全用 yaml 突出显示.我还注意到,使用我的配置 (MacVim 55),这也不适用于文本文件.

Unfortunately this does not work as expected i.e. the html code remains entirely highlighted with yaml. I've also noted that with my configuration (MacVim 55), this doesn't work in text files either.

感谢您的想法或建议,感谢您的阅读.

I'd be grateful for your thoughts or suggestions, and thank you for reading.

推荐答案

查看我的相关问题:使用Vim的syn-include和syn-region来嵌入语法高亮的问题.我正在尝试将 Python 嵌入到 TeX 中,但我认为该解决方案也可能适用于您的情况.

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'

如果您的 YaML 已经突出显示,则可能不需要带有 runtime! 命令的块.

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

这篇关于嵌套在 yaml 中的 html 的 VIM 语法高亮显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆