Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
yous opened this issue Feb 1, 2017 · 2 comments
Open

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

yous opened this issue Feb 1, 2017 · 2 comments

Comments

@yous
Copy link

yous commented Feb 1, 2017

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
Copy link
Owner

junegunn commented Feb 2, 2017

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
Copy link

tuurep commented Aug 25, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants