How to get multi-line syntax of a Vim clause?

I am trying to write a syntax highlighting module for a tiny text format that includes three different types of list items (starting with -, o and x, respectively), and I would like to highlight entries based on their type. For single lines, it's simple, I just use syn match myGroup /^\s\+- .\+/, and I'm done.

The problem is that I tried to do this so that the following lines without a list marker have the same color as the line in the original list, without any success. I tried to do this with syntax areas, but I can't figure out how they work.

To be more precise, this is the result I'm trying to achieve: enter image description here

If a change is required in the file format to make it easier / more possible, I have the freedom to change it.

Any clue to how I can get it?

+4
source share
1 answer

You can try something in this direction.

syntax region Minus_Region start=/^\s\+-/ end=/;/
hi Minus_Region guifg='Yellow'

syntax region O_Region start=/^\s\+o/ end=/;/
hi O_Region guifg='Green'

syntax region X_Region start=/^\s\+x/ end=/;/
hi X_Region guifg='Gray'

You define a region by its beginning and end (in this case ;), regardless of how many lines are involved.

For more information, see Help.

If you want to end regions without an end mark (in this case ;), you can do this by using the match-end ( me) option in the end argument of regions and having regions end on the next mark-march. Example:

syntax region Minus_Region start=/^\s\+- / end=/^\s\+[-ox] /me=s-1

syntax region O_Region start=/^\s\+o /  end=/^\s\+[-ox] /me=s-1

syntax region X_Region start=/^\s\+x /  end=/^\s\+[-ox] /me=s-1

me=s-1 " ".

+6

Source: https://habr.com/ru/post/1615409/


All Articles