Vim matching based on line start

I have a file in which a line can begin with + , - or * . Between some of these lines there may be lines (containing these characters, but not in column 1!) That begin with a letter or number (general text).

Knowing this, what will be the easiest way to set the matching and highlighting mechanism, so that a line that starts, for example, with + and all subsequent lines, to a line with + , - or * in column 1, will be highlighted in ... Red ?

Any ideas are welcome.

+4
source share
1 answer

You can use:

 syntax region MyRegion start=/^+/ end=/\ze\n[-+*]/ hi MyRegion guifg=red ctermfg=red 

If you want to integrate it with the current color scheme, use:

 hi link MyRegion Keyword 

(or comment, identifier, constant, etc.)

Note This means that the area ends on the line until the next - , + or * at the beginning of the next line. Therefore, the two areas starting with a + are adjacent, and you will not notice the difference in backlight.

If you want each area of ​​the line starting with + to be on the line ( inclusive ), starting with + , - or * , then use:

 syntax region MyRegion start=/^+/ end=/^[-+*].*/ 
+4
source

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


All Articles