Vim syntax highlighting for multi-line matching

I am implementing a syntax file on vim to highlight a hierarchy like this

| text at level 1
| | text at level 2
| | text at level 2
| | | text at level 3
| text at level 1

For example, I use

syn match myMatch +^\(| \)\++

to highlight level indicators. However, I would also like to highlight the wrong patterns like these

| text at level 1
| | | text at level 3

which increase levels by more than one. I wrote the following syntax match

syn match myWrongMatch +^\(\(| \)*\)\(\n\|[^|].*\n\)\1\(| \)\{2,}+

It may not be optimal, but it does the job. The problem is that matches are checked by vim on the line being edited, so if I correct the error by deleting the level in the second line, it will stop highlighting the second line, but still highlight the first one until I edit it (for example, delete and rewrite the character )

, , , . , , vim , ( )? , , .

. vim: syn-sync-linebreaks ( , ).

, , . , , . "linebreaks" . , break :

:syntax sync linebreaks=1

, . "linebreaks" . "minlines" , "linebreaks" .

.

+5
1

. , autocmd InsertEnter, , :

au InsertLeave * syntax synch minlines=50

. , autocmds. , , , .

: :h syn-sync , , , - , . , autocmd. , , , - autocmd - .

+2

All Articles