Vim HereDoc突出显示(Vim HereDoc Highlighting)

编程入门 行业动态 更新时间:2024-10-22 11:21:59
Vim HereDoc突出显示(Vim HereDoc Highlighting)

我想在bash heredoc中获得语法高亮。 另外,我想在heredoc中使用bash变量取消引用和命令替换突出显示。

使用这些说明作为起点,我能够通过检查sh.vim来添加变量解除引用。 我想你可以用类似的方式完成命令替换。

let s:bcs = b:current_syntax unlet b:current_syntax syntax include @YAML syntax/yaml.vim syntax region hereDocYAML matchgroup=Statement start=/<<-\?\s*\z(YML\)/ end=/^\s*\z1/ contains=@YAML,hereDocDeref,hereDocDerefSimple syn match hereDocDerefSimple "\$\%(\h\w*\|\d\)" syn region hereDocDeref matchgroup=PreProc start="\${" end="}" contains=@shDerefList,shDerefVarArray hi def link hereDocDeref PreProc hi def link hereDocDerefSimple PreProc

我的问题是,这似乎不适用于任何类型的块( if , function , for等)。 例如:

我唯一知道的是这不是缩进问题。 更改缩进没有任何效果,并且在块外部使用缩进可以正常工作。

I want to get syntax highlighting inside of a bash heredoc. In addition, I want bash variable dereference and command substitution highlighting in the heredoc.

Using these instructions as a starting point, I was able to add variable dereferencing by examining sh.vim. I imagine you could accomplish command substitution in a similar fashion.

let s:bcs = b:current_syntax unlet b:current_syntax syntax include @YAML syntax/yaml.vim syntax region hereDocYAML matchgroup=Statement start=/<<-\?\s*\z(YML\)/ end=/^\s*\z1/ contains=@YAML,hereDocDeref,hereDocDerefSimple syn match hereDocDerefSimple "\$\%(\h\w*\|\d\)" syn region hereDocDeref matchgroup=PreProc start="\${" end="}" contains=@shDerefList,shDerefVarArray hi def link hereDocDeref PreProc hi def link hereDocDerefSimple PreProc

My problem is, this doesn't appear to work in any sort of block (if, function, for, etc.). For example:

The only thing I know is that this is not an indentation problem. Changing indentation has no effect, and using indentation outside of a block works properly.

最满意答案

shIf定义的shIf似乎限制了shIfList组中任何项目的可能亮点。

将您的项目添加到组中,如下所示将突出显示该区域:

syn cluster shIfList add=hereDocYAML

所有其他块也适用相同的原则。 例如:

syn cluster shFunctionList add=hereDocYAML syn cluster shLoopList add=hereDocYAML

应该注意的是,您概述的方法通常并不常用。 首先,它要求包含的语法文件为其contains定义使用组。

此外,它适用于YAML,因为bash取消引用语法和YAML语法不冲突。 对于更复杂的语法(如sed或awk),您将遇到冲突,解决这些冲突的规则可能需要完全使用新语法。

The contains on the definition of shIf appears to limit the possible highlights to whatever items are in shIfList group.

Adding your item to the group as follows will give you highlighting withing that region:

syn cluster shIfList add=hereDocYAML

The same principle holds for all other blocks. For example:

syn cluster shFunctionList add=hereDocYAML syn cluster shLoopList add=hereDocYAML

It should be noted that the approach you've outlined is not generally useful. First of all, it requires that the included syntax file use groups for their contains definitions.

In addition, it works for YAML because bash dereference syntax and YAML syntax do not conflict. For more complicated syntaxes like sed or awk, you will have conflicts, and the rules to resolve those conflicts will likely require a new syntax entirely.

更多推荐

本文发布于:2023-08-04 11:33:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1415171.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Vim   HereDoc   Highlighting

发布评论

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

>www.elefans.com

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