嵌套在 yaml 中的 html 的 VIM 语法高亮显示

编程入门 行业动态 更新时间:2024-10-23 03:23:15
本文介绍了嵌套在 yaml 中的 html 的 VIM 语法高亮显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

给定一个包含 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屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 12:52:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1409374.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:嵌套   语法   yaml   html   VIM

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!