junegunn / vim-oblique

DEPRECATED Improved /-search (experimental)
83 stars 7 forks source link

Some patterns cause incorrect current match highlighting #46

Closed nkouevda closed 9 years ago

nkouevda commented 9 years ago

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:

nkouevda commented 9 years ago

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).

nkouevda commented 9 years ago

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?

junegunn commented 9 years ago

Superb, thanks! I'll apply your patch.