-1

This question already has an answer here:

I want to do substitution in a partial of a line.
But when I type :'<,'>s/xx/yy/g, it always do it in the whole line.
How can I tell vim to do it in the exact selection area??

marked as duplicate by statox, grodzik, Martin Tournoij Nov 23 '16 at 11:14

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

Add \%V to your search. From :h /\%V:

                        */\%V*
\%V Match inside the Visual area.  When Visual mode has already been
    stopped match in the area that |gv| would reselect.
    This is a |/zero-width| match.  To make sure the whole pattern is
    inside the Visual area put it at the start and end of the pattern,
    e.g.: >
        /\%Vfoo.*bar\%V
<   Only works for the current buffer.

So you want to do :'<,'>s/\%Vxx/yy/g

  • actually you want more something like :s/\%Vx\%Vx/yy/g – Christian Brabandt Nov 23 '16 at 7:02

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