I have a custom config that involves the following syntax:
key=value$(var)represents a variable
The $(var) part can appear in both key and value, i.e. message="hello $(FirsName) $(LastName)". The value part must be surrounded by double quote " if it contains space characters.
I want to match key, value and $(var) and highlight them separately in vim.
Here is what in my vim syntax file:
syn match configValue "\(\S\+=\)\@<=\"[^\"]*\"\|\(\S\+=\)\@<=\S\+"
syn match configKey "^\s*[a-zA-Z0-9_.]\+\(\s*=\)\@="
syn match configVar "\$(.*)"
The code successfully matches configValue and configKey, but not configVar if it is within key=value. This is ruled by the syntax match priority (h:syn-priority):
- When multiple Match or Region items start in the same position, the item defined last has priority.
- A Keyword has priority over Match and Region items.
- An item that starts in an earlier position has priority over items that start in later positions.
Rule 3 gives the other two matches higher priority than that of configVar.
My problem is that, how to match the three patterns separately, with configVar having the highest priority?