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


(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?


For a test case, you can use this file, then apply the same regex pattern above but for task_struct.

  • How do you mean highlight? You can’t see something not on screen (though splits can help).
    – D. Ben Knoble
    Commented Sep 27, 2021 at 20:05
  • Hey @D.BenKnoble , by highlighting I mean just when you do normal search / 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.
    – haxpor
    Commented Sep 27, 2021 at 20:11
  • 1
    I doubt multiline search would be highlighted more than some threshold (~a window height), you can use textproperties for that kind of highlighting
    – Maxim Kim
    Commented Sep 28, 2021 at 14:28
  • 1
    probably limits are similar to what is in this Q: vi.stackexchange.com/questions/12119/…
    – Maxim Kim
    Commented Sep 28, 2021 at 14:31
  • Thanks @MaximKim , also for info on 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!
    – haxpor
    Commented Sep 28, 2021 at 15:08


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.