Set item to higher highlight priority on vim

自闭症网瘾萝莉.ら 提交于 2019-12-05 04:22:19

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).

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

Someone already have answered the question. However, for others that are still having problems, here is another solution to highlight non-ascii characters in comments (or any group in the matter). It's not the best, but it's a temporary fix.

One may try:

:syntax match nonascii "[^\u0000-\u007F]" containedin=ALL contained |
            \ highlight nonascii ctermfg=yellow guifg=yellow

It's very close to the original implementation and other solution. You may even remove contained, but, from documentation, there may be potential problem of recursing itself (as I understand). To view other defined patterns, syn-contains section would contain it.

:help syn-containedin
:help syn-contains 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!