我想在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 PreProcMy 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=hereDocYAMLThe same principle holds for all other blocks. For example:
syn cluster shFunctionList add=hereDocYAML syn cluster shLoopList add=hereDocYAMLIt 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.
更多推荐
发布评论