Let's say I have the following fantasy code
// a long definition of a structure
struct long_struct {
...
};
There are tons of multiple lines inside such block of code. It cannot be displayed fully within a single page, but spans across multiple pages.
I would like to highlight all the lines inside such struct
definition without highlighting struct long_struct {
and };
. I successfully did it with the following regex
/\(^struct\s\+long_struct\s*{\n\)\@<=\(^.*\n\)\{-}\(^};\)\@=
(in short such regex makes use of positive lookbehind, and positive lookahead, with non-greedy \{-}
search.)
But the problem is that it will only highlights those lines that are able to be fit within a single page height. If I reduce the font size of terminal to fit more lines, it would be able to highlights additional lines as well. So I believe it's not the problem about above regex pattern.
How can I make vim able to highlight all those lines without limited by the number of lines shown on terminal screen?
Edit:
For a test case, you can use this file, then apply the same regex pattern above but for task_struct
.
/
and vim will highlight the search result and all occurrences. With that even when I move my cursor around, those highlighted occurrences from search are still there, highlighted, even not in current visible page.matchadd
which will limit to one screen highlighting. That seems like it. Using text property is somewhat overkill such that I have to implement a small function to achieve the same as normal search/
. Anyway, I will explore more about text property, thanks for bringing such topic up!