When I search for something with / I get a series of finds, and as I press n for next, it highlights the next one. I always think I'm on the wrong one. Maybe my eyes see green and red, and they think I'm on green. I don't know, but I have to adjust those two colors.

How do I do that? Code is also in the screenshot below...

enter image description here

I can only edit the green background by changing Search but I can't seem to change the red background which signifies the item I'm currently on.

  • 1
    Is this after you press enter? Are you using any plugin (beside your colorscheme) which could change highlights?
    – Biggybi
    Commented Apr 17, 2020 at 2:38
  • Yes, after I press enter. Commented Apr 17, 2020 at 17:48
  • Yes I am : ( searchant. Commented Apr 17, 2020 at 17:48
  • Without the plugin, my search results stay highlighted forever. 'Esc' doesn't remove them. Commented Apr 17, 2020 at 18:16
  • 1
    I don't know about searchant, but it could be a nice plugin to have. Use :nohl if you want to clear your highlights.
    – Biggybi
    Commented Apr 17, 2020 at 23:04

1 Answer 1


The current search colour is set by the IncSearch highlight group.
That's the colour you'll see, while typing your search, on the current item (by the way, you can use <c-t> and <c-g> while typing to select previous / next item).

But once you hit enter, vim should display only one colour (from the search group), so I guess you are using a plugin to display a different colour for the current item.


That was driving me crazy. I wrote a function that highlights the match in a different colour. Well, it's probably not the way to go, since a mapping is needed on n and N (and anything that starts a search, really), and it keeps the 'search hit bottom' from disappearing until the screen is moved.

Besides this caveat, it works quite fine.

function! HLCurrentMatch() abort
    call matchadd('IncSearch', '\c\%#'.@/, 101)
nnoremap <silent> n n:call HLCurrent()<cr>
nnoremap <silent> N N:call HLCurrent()<cr>

My vimscript skills are poor, but here's the main things to make it more viable in my opinion:

  • Check if we're back to the first match, in order to, say, use a different match, which would even be better than the 'back to first match' message
  • Enable it right when a new match is defined (with /, *, #...)


Here it is. This will use different highlight groups for the current match and for the edge matches. Courtesy to @Zorzi for his help on this question

function! HLCurrent() abort
    if exists("currmatch")
        call matchdelete(currmatch)
    " match only on cursor
    let patt = '\c\%#'.@/
    " check prev and next match
    let prevmatch = search(@/, 'bWn')
    let nextmatch = search(@/, 'Wn')
    " if on first or last match
    if prevmatch == 0 || nextmatch == 0
        let currmatch = matchadd('EdgeSearch', patt, 101)
        let currmatch = matchadd('IncSearch', patt, 101)
nnoremap <silent> n n:call HLCurrent()<cr>
nnoremap <silent> N N:call HLCurrent()<cr>

You'll need to define a "EdgeSearch" highlight group, for example:

highlight EdgeSearch guibg=green ctermbg=black

As for the "search hit bottom" message, it's not needed any more. It can be disabled with set shortmess+=s.

The code I use may change over time and can be found here.

  • 1
    Er, i think (i have to go check!) that with hlsearch on there are multiple colors (one for the active and one for all the others)
    – D. Ben Knoble
    Commented Apr 17, 2020 at 13:49
  • Okay, so removed the plugin. Things seem to work fine now, but... is there a way to affect the look of my current selection? Commented Apr 17, 2020 at 18:36
  • 1
    As I mentioned, and this is unfortunate, IncSearch does not seem to have any effect once the pattern is validated - but I may be doing something wrong.
    – Biggybi
    Commented Apr 17, 2020 at 23:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.