By :set hl, the search result of a / expression is highlighted, for example:

Vim search highlight in action

And if one wants to replace one substring distinguished by its surrounding, one can do so elegantly using regex capture groups:

replace not with and

However, the search highlight does not reflect this capture group. Sometimes, it would be very helpful if it did, so you can feel more confident about your attempted regex. Does Vim have such a feature?

  • You can't. The whole point of the hls setting is to give a visual clue what regex matches in your buffer. For highlighting capturing groups you would need 9 additional highlighting groups. – Christian Brabandt Aug 11 '18 at 15:53
  • 9 more groups does not seem excessive to me. But alright. :/ Wanna post that as an answer? – lindhe Aug 11 '18 at 15:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.