0

I was looking for a way to highlight lines above the cursor line to mark them as done, whatever that means in the context of what I'm doing.

I came up with this match Comment /\_.*\%#.*/ or, in words, highlight everything including newlines up until the cursor character, and then the rest of the line too as comment text

This does the job and allows me to easily progress through a document/source file by moving the cursor down, but the problem is: It's slow. REALLY slow.

Is there some better way to achieve the same result? I don't mind it involving a lot of magic, since I will most likely hide it away behind a function in my vimrc anyway, but I am restricted to only vimscript.

  • 1
    @Rich Ah, yes, that was a mistake. It's fixed now, thanks for pointing it out :) – DarkWiiPlayer Feb 2 '18 at 9:37
2

For me, simply using syntax matching by prepending syntax seems to make it acceptably fast:

syntax match Comment /\_.*\%#.*/

If that's not fast enough for you, perhaps you can alter your sync setting. See :help :syn-sync. I presumed this setting was why using syntax matching is faster than :match for this expression, but even using :syntax sync fromstart it still works fast for me (in the files I've tested it in).

If that's still no good, you could try setting up a syntax region instead:

syntax region Error start=/\%^/ end=/\%#.*/

This matches the beginning of the file and the cursor position, but nothing in between, so I imagine it would be super fast.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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