在vim上将项目设置为更高的突出显示优先级

我希望非ascii字符显示为 here所讨论的,但是当非ascii字符在注释中时,语法高亮消失.稍微调查一下这个问题,我在vim-manual上发现,先前启动的项目具有更高的优先级(第3项).来自帮助:syn-priority:

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

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

  2. A Keyword has priority over Match and Region items.

  3. An item that starts in an earlier position has priority over items that start in later positions.

我目前正在使用这个:

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

我尝试使用选项nextgroup给nonascii匹配项更高优先级:

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

并包含选项:

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

但它不起作用.我还尝试暂时禁用评论(突出显示清晰的评论)而没有达到预期的效果(我的评论没有突出显示,但是nonascii继续没有突出显示).我错过了什么?

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

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

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

相关文章

解决方案:解决linux下vim乱码的情况:(修改vimrc的内容)全...
Linuxvi/vim所有的UnixLike系统都会内建vi文书编辑器,其他的...
      vim正则匹配:空行:/^$/  /^[\t]*$/注释...
$select-editorSelectaneditor.Tochangelater,run'sele...
上次手贱忘了保存,这次就简单做个备忘吧,把踩过的坑记一下...
Linux之文本编译器小结vim的优势所有的UNIX-LIKE习通都会内置...