Reputation: 1665
I know I can do search and replace in horizontal selection with:
:'<,'>s/search/replace/g
But, I couldn't figure out how to do this in vertical selection. I tried the same method above by only having a vertical selection but, apparently, vim will search and replace to the entire line instead of just the selection.
Searched the internet to no avail. Thanks.
Upvotes: 5
Views: 1503
Reputation: 161604
You can use \%V
in your regex, it will match position inside visual area:
\%V Match inside the Visual area. This is a `/zero-width` match.
If you visual select a block:
search search search search
searc+---------------+earch
searc| search search |earch
searc| search search |earch
searc+---------------+earch
search search search search
After running this command:
:'<,'>s/\%Vsearch\%V/replace/g
It'll become:
search search search search
searc+---------------+earch
searc| replace replace |earch
searc| replace replace |earch
searc+---------------+earch
search search search search
Upvotes: 10