14

I have changed my Vim colours so when I do a /search, every match is highlighted in bright yellow. This makes matches much easier to see.

However, when I perform a substitution with the confirm flag like :%s/find/replace/gc all the items are highlighted in yellow, which is fine, but I can't tell which item Vim is asking me to confirm.

How can I highlight the current substitution item in another colour so I can see what needs confirming?

Heptite
  • 19,383
  • 5
  • 58
  • 71
jordelver
  • 2,251
  • 4
  • 23
  • 29

2 Answers2

10

The highlight group you want is "IncSearch" even if you don't have the the 'incsearch' option enabled—it is also used for the current substitution when confirmation is enabled.

See ":help hl-IncSearch".

Heptite
  • 19,383
  • 5
  • 58
  • 71
  • Thanks, that's exactly what I needed. I need to play around with colors now :) – jordelver Apr 13 '12 at 20:14
  • 1
    Follow up question. Is it possible to highlight matches when going through each one with `n` and `N` when just searching normally? – jordelver Apr 13 '12 at 20:46
  • I'm assuming you don't mean just enabling 'hlsearch'? I don't think the "current" match can be highlighted different than all matches, but I haven't needed it since the cursor moves to the current match with n/N. – Heptite Apr 13 '12 at 22:54
  • Sorry, wasn't clear. I've set different colours for `IncSearch` and `Search`. When I `/searchterm`, the match is highlighted in the `IncSearch` colour. When I hit enter so I can press `n` to jump to each match, all matches turn to the `Search` colour. What I want is to change the colour of each match as I jump to it. Does that make sense? :) This is what happens now with `:%s/find/replace/gc`. Each match is highighted a different colour as I press `y` or `n`. – jordelver Apr 14 '12 at 09:04
  • Yeah, like I said, there's no option to do this. I don't think it is considered necessary since the cursor is supposed to be on the current match in this context, and that should be a fairly clear indicator. – Heptite Apr 14 '12 at 18:06
  • Ok, thanks. Maybe I should change my cursor colour :) Thanks for your help. – jordelver Apr 14 '12 at 21:12
  • @Heptite, I don't know whether this option could be useful or not to experts, but it would be useful to beginners, to understand how a regexp works. Actually sometimes, when I write loooong regexps such an option would be useful. – Enlico Mar 11 '17 at 17:01
6

When inside vim you can use the command mode:
:highlight IncSearch guibg=green ctermbg=green term=underline

To have it always, put this into your .vimrc:
highlight IncSearch guibg=green ctermbg=green term=underline

p1100i
  • 960
  • 1
  • 9
  • 16