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