vehomzzz
vehomzzz

Reputation: 44568

How do you replace a word occurring on consecutive lines?

I usually either end up using [range]%s/word/another_word/gc or do it manually. I wonder if you guys use a different, perhaps a faster, way. Assume that I have vim 7.2.

Upvotes: 1

Views: 165

Answers (2)

Jonathan Leffler
Jonathan Leffler

Reputation: 753605

I usually use /word plus enter to find the word; cwanother plus ESC to replace it the first time; then n to find the next occurrence of the word (possibly a few times if it appears several times on the line and I don't want to change every one), and then . to repeat the last change.

I use the range based global search-and-replace when the occurrences are scattered throughout an extensive range and it is really global search-and-replace that I want.

Upvotes: 5

Michael Kristofik
Michael Kristofik

Reputation: 35188

& in command-mode repeats the previous search-and-replace command. You can also do things like 3& to repeat it over the next 3 lines.

Upvotes: 3

Related Questions