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.
EDIT
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)
redraw
endfunction
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
/
, *
, #
...)
FINAL
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)
endif
" 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)
else
let currmatch = matchadd('IncSearch', patt, 101)
endif
redraw
endfunction
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.
enter
? Are you using any plugin (beside your colorscheme) which could change highlights? – Biggybi Apr 17 '20 at 2:38