NOrder
NOrder

Reputation: 2493

how to edit highlight text in vim after searching

I like to use "*" to search text in vim. after hight light the target text, I want to edit all of them, is there any way I can do it in vim? for example, after highlight text, I just need to press ctrl+i then the highlight text can be edited simultaneously

Upvotes: 1

Views: 144

Answers (4)

Peter Rincker
Peter Rincker

Reputation: 45087

As a nice alternative. You can use gn and the . command.

  • Set your search pattern i.e. * or /foo
  • Change your highlighted pattern via c operator over the gn motion
  • cgnbar<esc> will change the highlighted area to bar.
  • Now you can use . too repeat this change. You can also use n to skip places.

Note: This requires at least 7.4

For more help see:

:h gn
:h .

Upvotes: 2

VijayD
VijayD

Reputation: 820

If you wish to edit the word with another you can use the substitute command. (e.g. :%s/hi/hello/g)

This will change all occurrences of hi to hello in the file.

Upvotes: 0

Conner
Conner

Reputation: 31040

You can check out the vim-multiple-cursors plugin.

Personally, I like @Ingo's solution. The less plugins the better.

Upvotes: 1

Ingo Karkat
Ingo Karkat

Reputation: 172510

Simultaneous editing (like seen in other editors) is not built into Vim (but there are plugins). You don't need them, though. After *, the text is stored in the last search pattern register, and you can just :substitute// without repeating what you're searching for:

:%s//replacement/g

The % is a range and applies this to the whole buffer; the /g is a flag that replaces all (globally) instances, not just the first in each line. Read :help :s for details.

Upvotes: 9

Related Questions