Pregunta

I know how to highlight long lines. Either :

:match ErrorMsg '\%>140v.\+'

which I rather prefer to the "colorcolumn way" :

:set colorcolumn=140

So, for instance, the text :

Vim is a text editor written by B. Moolenaar and first released publicly in 1991. It is based on the vi editor common to Unix-like systems. Vim is free and open source software.

gets highlighted starting with "Vim is free, etc…"

But how can I achieve the same result for a paragraph (in this example, 3 lines) such as :

[Empty line]
Vim is a text editor written by B. Moolenaar and first released publicly in 1991. 
It is based on the vi editor common to Unix-like systems. 
Vim is free and open source software
[Empty line]

Thanks in advance

¿Fue útil?

Solución

This is difficult, because you have to specify (in a single regular expression)

  1. the condition of paragraphs (which I assume to be lines separated by at most a single newline; i.e. empty lines create new paragraphs)
  2. the counting of characters (highlight after 140 characters)

Here's the best I've achieved; it still somehow matches "into" following paragraphs if the current one is too small:

:match ColorColumn /\%(\%^\|\n\n\)\%(\%(.\+\n\)*.*\)\&\_.\{140}\%(\zs.\|\n\zs.\)/

Explanation:

  • anchored at the beginning of the buffer or an empty line
  • match non-empty line(s)
  • and additional characters AND
  • match 140 characters and/or newlines
  • then start a match on the following character, or if that it a newline (which doesn't show up right), the next character after it

I'd be happy if someone improves on this.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top