Aratz
Aratz

Reputation: 440

How to highlight newly replaced text in vim

After I do a replace, I'd like vim to highlight the text that has just been changed (instead of the words that match my search). Say, if I type s/old/new/, I want new to be highlighted (instead of old). Is there any ways to do that?

I thought about triggering a search on new after the replace step but that would also highlight the words that were already in the text before.

Upvotes: 0

Views: 247

Answers (2)

Ingo Karkat
Ingo Karkat

Reputation: 172540

If you only want highlighting of those instances that were replaced (not all new ones), you have to write your own :Substitute command that records each change position (via :help sub-replace-expr), and then builds a regular expression that only matches at those positions (using \%l and \%c). Doable, but quite involved.

You probably know this feature from other editors; try to live without it, it's not essential.

Upvotes: 1

Arithran
Arithran

Reputation: 1279

The command separator in vim is |

You can run the search after the replace in the same line

:s/old/new/ | /new

Upvotes: 0

Related Questions