pim
pim

Reputation: 12567

Vim search & replace (all) from text selected in visual mode

I'm curious if it's possible, using Vim, to engage a search & replace based on text selected in Visual mode?

For example, if I have public int Id; selected in visual mode. Is it possible to perform a search & replace (all instances) without having to retype public int Id; into the :s[ubtitute]/{pattern}/{string} command?

Upvotes: 2

Views: 724

Answers (2)

Stark
Stark

Reputation: 61

Maybe you could have a look with this vim plugin terryma/vim-multiple-cursors. For your case, just select that blocks, then press several times, there'll be several cursors highlight those blocks, you could edit time at the same time.

Upvotes: 0

possum999
possum999

Reputation: 81

Use such mapping:

 vnoremap <Leader>zr :<c-u>%s/<c-r>*

Selected text is in the selection buffer already, so we paste it with ^r*

<c-u> cleans the command prompt

Upvotes: 1

Related Questions