Vim 语法文件……试图理解“包含" [英] Vim syntax files ... trying to understand "contains"

查看:25
本文介绍了Vim 语法文件……试图理解“包含"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我正在使用的某些自定义格式修补一个新的 vim 语法文件.大部分我都能理解,但是关键字包含"给我带来了麻烦.

I'm trying to patch up a new vim syntax file for some custom format I'm using. Most of it I can understand, but the keyword "contains" is giving me trouble.

这里有没有人可以向我解释它的作用(我已经阅读了帮助 -> 不太明白),就像他在向一棵树解释一样.

Is there anyone here who could give me an explanation of what it does (I've read the help -> didn't quite get it) in a way as if he were explaining it to a tree.

推荐答案

一般来说,一个地方只能有一种语法高亮方法.因此,以类似 C 的语法为例,如果您定义一个区域以开始于左大括号 '{' 并结束于右大括号 '}',则该区域的语法突出显示将相同.

In general, you can only have one syntax highlighting method in one place. Therefore, to use C-like syntaxes as an example, if you define a region to start on an opening brace '{' and end on a closing brace '}', the syntax highlighting for that region will be the same.

contains= 允许您配置要包含在外部组中的其他语法高亮组.按照前面的示例,您可能希望 int 即使在外部区域中也能突出显示.然后你可以有类似的东西:

contains= allows you to configure other syntax highlighting groups to be contained within an outer group. To follow the previous example, you may want int to be highlighted even when it is in the outer region. You could then have something like:

syn keyword Keyword int
syn region BraceBlock start='{' end='}' contains=Keyword

稍后需要将项目添加到包含的关键字列表中是很常见的.有几种方法可以做到这一点.首先,您可以使用 contains=ALLcontains=ALLBUT,Error 来允许区域中的任何内容.其次,您可以使用 containedin 将某些内容推送到另一个区域的包含中:

It is quite common to need to add items later to the list of contained keywords. There are a few ways of doing this. Firstly, you can use contains=ALL or contains=ALLBUT,Error to allow anything to be in a region. Secondly, you can use containedin to push something into the contains of another region:

syn region BraceBlock start='{' end='}'
syn keyword Keyword int containedin=BraceBlock

第三,您可以将包含"的任何内容定义为在该组中有效:

Thirdly, you can define anything that is "contained" as valid in this group:

syn region BraceBlock start='{' end='}' contains=CONTAINED
syn keyword Keyword int contained

最后,您可以使用集群,这可以很容易地决定什么去哪里:

Finally, you can use clusters, which make it quite easy to decide what goes where:

syn region BraceBlock start='{' end='}' contains=@MyCluster
syn keyword Keyword int
syn cluster MyCluster contains=Keyword
syn keyword Conditional if else
syn cluster MyCluster add=Conditional
" Now conditionals and keywords can appear in a BraceBlock

在不知道您想了解什么的情况下,我不知道还能说什么 - 您想达到什么目的以及是什么导致了您的问题?

Without knowing exactly what you want to understand, I'm not sure what else to say - what are you trying to achieve and what is causing you problems?

这篇关于Vim 语法文件……试图理解“包含"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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