vim语法优先级可以颠倒吗?
以下是vim语法优先级可以颠倒吗?,vim,vim-syntax-highlighting,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 Keywo
: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.
您正在查找嵌套匹配工具,请参见
:help syn contains
:syntax match boldme /\*[^*]\+\*/
:syntax match nTODO /^\s*!!.*/ contains=boldme
无论是否包含,我仍然希望在boldme上进行匹配,因此看起来我必须为
innerBold
定义两次匹配,一次使用contained
关键字,一次不使用关键字。我接受,因为它解决了问题,但是如果你知道没有冗余的方法,请更新。我错过了这个,我将留给我的神经病理学家,但事实证明“包含”关键字不是必需的。