Vim 自定义语法仅高亮背景
我想在 Vim(GUI 版本)中自定义语法突出显示。我的语言有一个现有的语法文件。我想添加到该语法中,如果该行以 >
开头,则突出显示每行的背景颜色。我发现我基本上可以通过
:syntax match Output /^>.*$/
添加
:hi Output guibg=LightBlue
颜色方案来实现这一点。这些 Output
行中的文本背景颜色变为浅蓝色,但它也会覆盖前景色。所以大部分语法高亮都会消失。如何在这些行中保持前台语法突出显示?
另外:有没有办法将背景的突出显示延伸到这些行的末尾(屏幕的右端)?
I want to customize syntax highlighting in Vim (GUI version). There is an existing syntax file for my language. I want to add to that syntax highlighting a background colour to each line if that line starts with >
. I figured out that I can basically achieve this by
:syntax match Output /^>.*$/
and adding
:hi Output guibg=LightBlue
to the colourscheme. The background of the text in these Output
lines gets coloured then in light blue, but it overrides the foreground colour as well. So most of the syntax highlighting disappears. How can I keep the foreground syntax highlighting in these lines?
Also: Is there a way to extend the highlighting of the background to the end (right end of the screen) of these lines?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以下是如何保留语法,我匹配以
{
开头的行编辑: 因为您想要相反的效果,所以您需要
Here is how to preserve the syntax, I'm matching lines starting with
{
Edit: since you want the opposite you need
试试这个:
Try this:
正如 Eric Fortis 所指出的,实现您所寻找的内容的最简单方法是使用
:match
命令。据我所知,通过语法突出显示实现此目的的唯一方法将要求您像当前所做的那样匹配整行。然后,您需要使用
contains=...
修饰符指定您的行中可以包含哪些语法元素。我也非常确定这些元素需要为其分配contained
属性。这样,在行中找到的任何元素(即与.*
匹配的元素)都将保留其突出显示。请参阅
:help :syn-contains
了解更多信息。The easiest way to achieve what you're looking for is with the
:match
command as Eric Fortis has pointed out.The only way I know of to achieve this with syntax highlighting will require you to match the entire line as you are currently doing. You will then need to specify, using the
contains=...
modifier, which syntax elements can be in your line. I'm also pretty sure these elements will need to have thecontained
attribute assigned to them. This way any element found in your line i.e matched by the.*
will preserve it's highlighting.See
:help :syn-contains
for more.