visually select A "ay
, visually select B "by
then :s/<ctrl-r>a/<ctrl-r>b/g
Note: pasting in from register produces ^M
and ^I
in place of newlines and tabs. These need to be converted to \n
and \t
respectively.
(Technique also documented here: http://vim.wikia.com/wiki/Search_and_replace)