If you want to select some lines of text and search for a word to replace in Vim, many users will do it like this:
- Use
v
to do the selection. - Press
:
to start inputting an editor command. - Use
s/<pat>/<text>/g
to search and replace text.
Observation: :'<,'>s
“applies to whole lines”.1
How about an arbitrary visual selection?
According to a Vim tips found in the footnote, the answer is quite
simple—insert the \%V
atom at the beginning of the search pattern.
-
Search and replace in a visual selection—Vim Tips Wiki ↩