以下是: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.
答案 0 :(得分:1)
您在嵌套匹配工具之后,请参阅:help syn-contains
:syntax match boldme /\*[^*]\+\*/
:syntax match nTODO /^\s*!!.*/ contains=boldme