#21354·vim

matchparen: improve match update mechanism

Author: rendcrxCreated Sep 21, 2026Updated Sep 21, 2026
Labelsenhancement

I mentioned this problem in a previous issue https://github.com/vim/vim/issues/20791, but at that time I did not provide a reproduction method.

If we have a '()' in a file a.c and open it with:

vim --cmd 'autocmd TextChangedI * sleep 3' a.c

then type text inside the (), we can see that the highlight stays in the wrong position the whole time.

Image

The current matchparen mechanism removes the previous highlight after the text has changed, then recomputes the highlight and renders it. This means there is inevitably an intermediate moment where the highlight is wrong.

If the machine is slow, or if more work is added in TextChangedI, this becomes clearly visible. In particular, if the previous highlight position is replaced by a tab, it can go from one wrong highlight position to eight cells being highlighted at once, which is very noticeable.

I think that even when the computation is slow or there is a lot of work to do, it should still be possible to avoid showing an incorrect highlight.

After switching to a display with a lower refresh rate, I started seeing this intermediate incorrect highlight very frequently, and it became clearly visible.

I am not sure what the best update mechanism would be, but reducing the number of renders and avoiding any intermediate incorrect display seems like a good direction.

In the current matchparen, just entering a file triggers two highlight computations, and in Insert mode, typing a single character also triggers two highlight computations. I suspect this is because cursor movement and text change are both causing recomputation.

I understand this may be difficult to solve and the impact is limited, but I wanted to report it in case it can be improved.