The command :'<,'>s/search/replace/g will replace in the whole line of the current selection, but what if I want to substitute only inside the current selection, not the whole line?

Update: Found the duplicate.


1 Answer 1


Use :'<,'>s/\%Vsearch/replace/g

From help substitute:

For the definition of a pattern, see |pattern|.  In Visual block mode, use
|/\%V| in the pattern to have the substitute work in the block only.
Otherwise it works on whole lines anyway.

Not the answer you're looking for? Browse other questions tagged or ask your own question.