vim语法优先级可以颠倒吗?

时间:2014-05-17 08:52:42

标签: vim vim-syntax-highlighting

以下是:help syn-priority的条目。

PRIORITY                        *: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.

似乎规则3似乎会覆盖规则1

是否可以使规则1优先于规则3?

以下是不良行为的具体示例。使用以下语法文件,似乎nTODO的优先级高于boldme

syntax clear
syntax case match

syntax match nTODO /^\s*!!.*/ 
syntax match boldme /\*.\+\*/

highlight nTODO  ctermfg=Yellow
highlight boldme ctermfg=Red

匹配的示例输入:

This *line* has one word Red.
!!This line is completely yellow.
!!This line is also *completely* yellow, but I want one word to be red.

1 个答案:

答案 0 :(得分:1)

您在嵌套匹配工具之后,请参阅:help syn-contains

   :syntax match boldme /\*[^*]\+\*/
   :syntax match nTODO /^\s*!!.*/ contains=boldme