Vim: How to change the current item highlight color when substituting

11

2

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?

jordelver

Posted 2012-04-13T15:35:35.193

Reputation: 1 781

Answers

7

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

Posted 2012-04-13T15:35:35.193

Reputation: 16 267

@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. – Enrico Maria De Angelis – 2017-03-11T17:01:59.663

Thanks, that's exactly what I needed. I need to play around with colors now :) – jordelver – 2012-04-13T20:14:13.297

1Follow up question. Is it possible to highlight matches when going through each one with n and N when just searching normally? – jordelver – 2012-04-13T20:46:59.337

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 – 2012-04-13T22:54:10.313

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 – 2012-04-14T09:04:41.540

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 – 2012-04-14T18:06:38.993

Ok, thanks. Maybe I should change my cursor colour :) Thanks for your help. – jordelver – 2012-04-14T21:12:21.803

2

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

Posted 2012-04-13T15:35:35.193

Reputation: 700