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

Add highlight group for current match #2819

Closed
alok opened this issue Apr 19, 2018 · 9 comments
Closed

Add highlight group for current match #2819

alok opened this issue Apr 19, 2018 · 9 comments

Comments

@alok
Copy link

alok commented Apr 19, 2018

After patch 8.0.1238, it would be nice if the current match had its own highlight group (that could be linked by default to the regular Search hl group).

@brammool
Copy link
Contributor

Which patch do you refer to? Patch 8.0.0128 is: Display test fails on MS-Windows.

@alok
Copy link
Author

alok commented Apr 19, 2018

Sorry, missing a digit: I meant 1238.

@jparise
Copy link
Contributor

jparise commented Jan 9, 2019

The Loupe plugin does this:

Makes the currently selected match easier to see

When searching using /, ?, star, #, n, N or similar, it can be hard to see the "current" match from among all the matches that 'hlsearch' highlights. Loupe makes the currently selected match easier to see by:

  • Applying a different :highlight group (by default, hl-IncSearch) to the match under the cursor.

It implements this using matchadd() to highlight the current match, but it would also make a nice addition to vim itself.

@jparise
Copy link
Contributor

jparise commented Feb 13, 2019

There's also a recent r/vim thread that suggests the vim-searchhi plugin as well as an ad hoc scripting solution.

@qxxxb
Copy link

qxxxb commented Feb 16, 2019

There's also vim-searchlight, which uses no mappings

@blueyed
Copy link

blueyed commented Sep 23, 2019

For reference, there's a WIP PR for Neovim at: neovim/neovim#11082

@brammool
Copy link
Contributor

It's not really the current match, more like the "last found match". If you move the cursor around and hit "n" then only the cursor position matters, not what was found last.
Using IncSearch has the disadvantage that this highlight will always happen, not only when the user specifically adds highlighting for it.

jparise added a commit to jparise/dotfiles that referenced this issue Jul 9, 2020
Loupe provides a really nice search experience, but it has two
downsides based on how it's currently implemented:

1. It remaps most of the built-in search commands.
2. Due to 1, we lose vim's built-in `[x/y]` search statistic.

Neither of these is a major issue, but I thought I'd explore
alternatives nonetheless.

I ultimately found good results with vim-searchlight (to make the
current match more visible) and vim-cool (to turn off highlighting when
the cursor moves off of a match).

I no longer center search results, but I could easily restore that
behavior with something like `nnoremap n nzz`, et al.

It would be great if vim provided the ability to distinctly highlight
the current match, which would make vim-searchlight redundant. That's
being tracked as vim/vim#2819.
LemonBoy added a commit to LemonBoy/vim that referenced this issue Apr 9, 2022
The aim of CurSearch is to let the user highlight the current match
without having to resort to overcomplicated plugins to approximate this
simple feature.

Closes vim#2819
@airblade
Copy link

airblade commented Apr 20, 2022

I'll throw my hat in the ring: https://github.com/airblade/vim-current-search-match

Update: never mind, I just saw 8.2.4724.

@chrisbra
Copy link
Member

Closing then: a43993897aa372159f682df37562

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

Successfully merging a pull request may close this issue.

7 participants