junegunn / vim-slash

Enhancing in-buffer search experience
MIT License
332 stars 33 forks source link

Search highlight is not cleared when there is no match #5

Open yous opened 7 years ago

yous commented 7 years ago

Recently I experienced an issue multiple times. When I search something and there is no match in the current buffer, then search highlight is not cleared even if I move the cursor.

This is the minimal vimrc to reproduce:

set nocompatible
filetype off

call plug#begin()
Plug 'junegunn/vim-slash'
call plug#end()

Open Vim and search anything, for example, /test. Then we'll see E486: Pattern not found: test error. Just insert that text, test to the buffer. Then it'll be immediately highlighted. If I turn off the search highlight, I need to type :noh or search that term again and move the cursor.

This issue is clearer when there are multiple windows open. One having no match, and the other having one match or more. If the current buffer doesn't have a match, then the search highlight of the other is not cleared when I move the cursor.

junegunn commented 7 years ago

Thanks, I can reproduce. Vim stops processing the rest of the sequence on error (see :help map-error), so that's why in that case slash fails to register the autocmd for clearing the search highlight.

gd also has the same issue. If you press gd on the first occurrence of a keyword, it will fail and highlighting will remain. Unfortunately, I'm not aware of a solution to the problem.

tuurep commented 1 year ago

Possibly related (?):

Using :substitute

Substitute and re-insert substituted:

  1. :%s/something/idontknow/g
  2. Now insert "something" again
  3. "something" is highlighted and won't clear

Substitute with 'confirm' flag (c):

  1. Have a bunch of "something"s
  2. :%s/something/idontknow/gc
  3. On some of the confirms, press n (no)
  4. Elements you chose not to substitute are highlighted and won't clear

The first scenario is quite rare, but for those who use the c flag a lot, it's a bigger issue.

Edit: Also using a line range (e.g. :1,10s///g will highlight matches outside of the range and won't clear

Anyway, are the substitute issues similarly not possible to solve? I'm interested in finding solutions.