Reputation: 123
I have a file format where the first word of each line has special meanings. I want to write a .vim
file to customise such syntax highlight. I read some tutorial about highlight keywords or matches. But it seems that there is not an explict way to solve my problem. Does anyone know how to implement it?
Upvotes: 1
Views: 1168
Reputation: 16188
You need to create a syntax matcher, and then link that to a highlight.
syn match startLineMatch /^\s*\w\+/
hi def link startLineMatch Error
This will highlight the first word on every line.
/^\s*\w\+/
matches the start of the line ^
then any amount of whitespace \s*
and then one or more word characters \w\+
. A word character is equivalent to [a-zA-Z]
. If you want match any none whitespace character you can use \S
instead of \w
.
In this case I have reused (linked) the highlighting definition for Error for our custom highlight definition for start of line match.
This method won't work if you are trying to override existing highlight groups, as the a syn keyword
has a higher priority in the syntax highlighting than syn match
. You will have to remove the existing keyword highlighting to get your new match to work.
Upvotes: 1