junegunn/vim-oblique

Some patterns cause incorrect current match highlighting

nkouevda opened this issue · 3 comments

It is necessary for s:highlight_current_match to prefix pat with s:prefix_for(pat, highlight_all) before calling s:matchadd, but this has some unintended side effects:

  • If pat is *, then the resultant pattern is something like \c\%1l\%1c*, so the * becomes a quantifier.
  • If pat begins with ^, the resultant pattern no longer matches at the beginning of the line.

A potential fix would be to surround pat with \( and \) (note that \%( would not work):

@@ -341 +341 @@ function! s:highlight_current_match(...)
-  silent! call s:matchadd(group, s:prefix_for(pat, highlight_all) . pat)
+  silent! call s:matchadd(group, s:prefix_for(pat, highlight_all) . '\(' . pat . '\)')

This solves the issues I mentioned above, but introduces others (e.g. references like \1 break).

A branch separator would be better:

@@ -341 +341 @@ function! s:highlight_current_match(...)
-  silent! call s:matchadd(group, s:prefix_for(pat, highlight_all) . pat)
+  silent! call s:matchadd(group, s:prefix_for(pat, highlight_all) . '\&' . pat)

I haven't yet found any downsides to this approach. What do you think @junegunn?

Superb, thanks! I'll apply your patch.