在vim上将项目设置为更高的突出显示优先级 [英] Set item to higher highlight priority on vim

查看:32
本文介绍了在vim上将项目设置为更高的突出显示优先级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 此处显示非 ascii 字符,但是当非 ascii 字符在注释中时,语法高亮消失.稍微调查一下问题,我在 vim 手册中发现,较早开始的项目具有更高的优先级(第 3 项).来自 help :syn-priority:

I want to non ascii characters to show as discussed here, but the syntax highlight disappears when the non ascii character are inside a comment. Investigating a little the problem, I've discovered at the vim-manual that an item that starts earlier has higher priority (3rd item). From help :syn-priority:

当多个语法项可能匹配时,使用以下规则:

When several syntax items may match, these rules are used:

  1. 当多个 Match 或 Region 项目在同一位置开始时,最后定义的项目具有优先权.

  1. When multiple Match or Region items start in the same position, the item defined last has priority.

关键字优先于匹配和区域项目.

A Keyword has priority over Match and Region items.

我目前正在使用这个:

syntax match nonascii "[^\x00-\x7F]" 
highlight nonascii cterm=underline ctermfg=red ctermbg=none term=underline

我尝试使用选项 nextgroup 为 nonascii 匹配项赋予更高的优先级:

I tried to give higher priority to nonascii match item using the options nextgroup:

syntax match nonascii "[^\x00-\x7F]" nextgroup=Comment

contains 选项:

syntax match nonascii "[^\x00-\x7F]" contains=ALL

但是没有用.我还尝试暂时禁用评论(highlight clear Comment),但没有达到预期的效果(我的评论没有突出显示,但 nonascii 继续未突出显示).我缺少什么?

but it didn't work. I also tried to disable comments temporarily (highlight clear Comment) without the desired effect (my comments got without highlight, but the nonascii continued unhighlighted). What I am missing?

推荐答案

是的,您的自定义语法组不匹配,因为注释(或现有语法脚本中的其他语法元素)已经匹配.

Yes, your custom syntax group isn't matched because there's already a match for comments (or other syntax elements from the existing syntax script).

解决方案是告诉 Vim 你的 nonascii 组是 containedin 那些组,这样 Vim 将尝试匹配那里(而不仅仅是在未着色的顶级), 也.更复杂的是注释的语法组取决于语法脚本,因此取决于文件类型(命名非常规则).在以下示例中,我使用了 C 和 Vimscript 文件的名称:

The solution is to tell Vim that your nonascii group is containedin those groups, so that Vim will attempt to match there (and not just at the uncolored top level), too. What's complicating this is that the syntax group for comments depends on the syntax script and therefore on the filetype (those the naming is quite regular). In the following example, I've used the names for C and Vimscript files:

:syntax match nonascii "[^\x00-\x7F]" containedin=cComment,vimLineComment

这篇关于在vim上将项目设置为更高的突出显示优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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