Here is the entry for :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.
It appears that rule 3
seems to override rule 1
.
Is it possible to make rule 1
take precedence over rule 3?
Here is a concrete example of the undesirable behavior. Using the following syntax file, it seems that nTODO
has a higher priority than boldme
.
syntax clear
syntax case match
syntax match nTODO /^\s*!!.*/
syntax match boldme /\*.\+\*/
highlight nTODO ctermfg=Yellow
highlight boldme ctermfg=Red
Example input to match on:
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.
You're after the nested-match facility, see :help syn-contains
:syntax match boldme /\*[^*]\+\*/
:syntax match nTODO /^\s*!!.*/ contains=boldme