3

Assume we have this text:

baaa

matchaddpos("Error", [[1,2]]) highlights the second character (the first 'a') as "Error" group.

baaa
 ^ highlighted

When I insert a 'b' at the beginning, it becomes

bbaaa
 ^ highlighted

It looks like the color is stick to the "grid" instead of the character underneath.

What I wanted is this:

bbaaa
  ^ highlighted

That is, is there a "thing" that, when I call thing("Group", [[lnum,col]]), the color is added to the character at that position, so that even when the character moves, the color follows it?

  • 4
    no, not possible. This was discussed briefly, when matchaddpos() was introduced, but nobody really was interested in implementing it. – Christian Brabandt Jul 21 '16 at 6:28
  • What do you intend to use this for? – Antony Jul 21 '16 at 7:01
7

You can't do that with matchadpos(). This is a known problem with Vim highlighting, and it isn't likely to be solved any time soon.

The best you can do is to use matcadd() with a regexp that matches on line 1, and anchor it at the first a. Perhaps like this:

:call matchadd('Error', '\%1l[^a]\zsa')
0

Now it's partially possible (adapts to line insertions and deletions only) with NeoVim!

From Neovim Newsletter #7 - Summer of Road:

  • buffer-local highlighting (:help api-highlights) is similar to matchaddpos(), with some key differences: it is associated with a buffer and adapts to line insertions and deletions. Useful for linter or semantic highlighter plugins that monitor a buffer for changes and compute highlights in the background.

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.