alfredodeza
alfredodeza

Reputation: 5188

Multi-line Highlight in Vim

I am currently writing a plugin in Vim that needs to highlight arbitrary lines in a file at the same time.

My approach so far has been implementing match with the line number to highlight it, but the problem is that I would need to add | for every other line in a file and append that information and then call it every time the window gets redrawn.

There is another problem with match in my case, and that is that a line that may not have any whitespace would not look highlighted (match only highlights existing text/whitespace).

So even if I had match rewrite the window and highlighting all the lines I need, from a user's perspective this wouldn't be to useful if the highlighting doesn't show anything if there is no whitespace/text.

Can I get any suggestions in how to effectively show/display/highlight (I'm open to different implementations to solve my problem) arbitrary lines in a file at the same time regardless of amount of text or whitespace?

Edit: My main request is to be able to highlight lines by line number not by regex matching. So any solution should need to be flexible enough to accept a Line number to match.

Edit: signs is the answer to my problem, and I found this tutorial the best way to grasp and implement what I needed: http://htmlpreview.github.io/?https://github.com/runpaint/vim-recipes/blob/master/text/07_navigation/12_bookmarking_lines_with_visible_markers.html

Upvotes: 2

Views: 1459

Answers (1)

shawnhcorey
shawnhcorey

Reputation: 3601

I would use region rather than match. Here is part of my manuscript syntax file that highlights speech:

:syntax region msSpeech start=/"/ end=/"\|\n\n/
:highlight msSpeech guifg=#000088

It starts with a double quote and ends with another double quote or the end of the paragraph. It will highlight multiple lines if need be.

Upvotes: 2

Related Questions