I'd like to highlight sections of a document which are too long (measured in lines) so they will all print on a physical page. Sections are separated with ===. I tried to do it with this code:

matchadd('ErrorMsg', '\%(^\|===\n\)\%(.*\n\)\{5}\zs\%(.*\n\)\+\ze', -1)

Everything works hunky-dory. But when I increase the size:

matchadd('ErrorMsg', '\%(^\|===\n\)\%(.*\n\)\{80}\zs\%(.*\n\)\+\ze', -1)

matches don't highlight. From the documentation :matchadd:

Defines a pattern to be highlighted in the current window (a

Based on figuring out where exactly the problem happens, I think it's not using text outside the current window. What should I be doing instead? Sections are already associated with folds if that helps.

  • I think you are misunderstanding what window actually means. Also, I think your regex is wrong, but this depends on an actual example and you didn't give one. – Christian Brabandt Apr 19 '17 at 10:53

How about :au BufWinEnter * let w:m1=matchadd('ErrorMsg', '\(^===\)\_p\{20,}\1', -1) ?

This works with my little lorem ipsum test case.

The solution here is \_p\{20,}, which matches at least 20 printable characters including newline (that is the _).

I tried this with a little "lorem ipsum", consecutive blocks are also highlighted, which makes the whole affair quite colorful...

  • This is testing for 20 printable characters--I want to match 20 lines, I'm not sure what you were understanding me as asking, but my original regex is already correct. Is your window more, or less, than 20 rows tall? If your individual matches fir on the screen, you are not duplicating the problem I describe. – Zachary Vance Apr 19 '17 at 3:27

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.