How to restrict visually selected replace
Make a visual selection in vim, then type
:. You can do a search and replace by the normal means:
The only problem with this is that it defaults to the whole line. So if, for example, you are trying to replace the
/ character within a selection on a line of an HTML or template file, this will screw up the closing tag of that line.
The trick here is to use
%V in the matching portion.
This restricts the match criteria to just the selection! Checkout