I have a file in the following format:
Abc Task Header:
- task detail a
- task detail b
Def Task Header:
- task detail c:
- task sub detail c1
- task sub detail c2
- task detail d
I would like to have my syntax file match (and highlight) the following lines:
Abc Task Header:
Def Task Header:
I do not want the following line to matched and highlighted:
task detail c:
Things to note:
- All tasks headers start with a letter and end with a colon.
- Task headers do not have any consistent naming convention other than the one listed above (so there is no
Task Headerin the name… This was just an example name) - Task details may end in a colon if they have sub task details.
- Task details always start with a
-(dash) character. - Task details are not indented. This was a side effect of the StackOverflow editor when using lists.
- All bullets shown are actually
-(dashes) in the file. This was also a side effect of the StackOverflow editor.
I have tried a few things, but they don’t seem to be working properly.
e.g.
syn match myTask "[A-Z]*:$"
This results in highlighting only the last word for the task header, as well as the colon. It also highlights any task details that have a colon.
syn match myTask "[^-].*[A-Z].*:$"
This results in highlighting the entire task header and colon (wanted behaviour), but highlights any task detail containing a colon. It does not highlight the dash, but highlights the rest.
Any ideas?
Thanks
UPDATE:
Well, Billy Moon’s example is straight to the point and covers the one scenario that will always be true. However, there were some other answers that worked as well (thanks YGomez). I’ll add some samples on here based on these or ones I managed to get work after some inspiration from other answers (in case someone else is looking for a solution to a similar problem in the future);
syn match myTask "^[^-].*:$"
syn match myTask "[A-Z]*:$"
syn match myTask "^\s*[A-Z].*:$"
// These two are equivalent.
syn match myTask "^\s*[A-Za-Z].*:$"
syn match myTask "^\s*\c\w.*:$"
Try this: