I have already asked a question about syntax highlighting, but this seems (to me) to be different and I could not find the answer in Stackoverflow.
1) Suppose I want to build a Todo list in Vim. This Todo list should have the task + 3 differently highlighted “regions” :
- the task (e.g. wash the car), always at the beginning, should remain plain non-highlighted text
- the person who has to do that thing – myself – preceded by @. I want it to be highlighted in (e.g.) green
- the category of the task – here Household – preceded by §. I want it to be in yellow
- the importance of the task – here Later -, preceded by # which I want to be red.
Thus the result should be (in one line) :
Wash the car @myself (green) §Household (yellow) #Later (red)
I have tried to define a first region starting with @, ending with §, a second starting with § and ending with #, and a third starting with # and ending with $.
:syntax region xPers start ='@' end='§'
hi xPers ctermfg=DarkGreen
:syntax region xProject start ='§' end='#'
hi xProject ctermfg=DarkYellow
:syntax region xImportance start ='#' end='$'
hi xImportance ctermfg=DarkRed
To no avail… All the indications that comes after the task itself, starting with @ are highlighted in green.
What are my (unforgivable) errors ?
2) To make things more complicated, I might write tasks down in a disorderly way, and write :
Wash the car @myself (green) #Later (red) §Household (yellow)
How should the syntax be defined to take this lack of discipline in consideration, and keep the colors right ?
Thanks in advance
You might want to take a look at Todo.txt and the vim syntax file for Todo.txt. However, as per your question, it seems like you want to end with a space instead of a symbol. So you could do this:
however this won’t account for the end of a line. So you could put an “or” statement in there for the end of the line like this: