Is it possible to use find and replace on a wildcard string in VIM?
I believe you want
:%s/foo\(\w\+\)Bar/& = \1 + \1\Old/
explanation:
\w\+
finds one or more occurences of a character. The preceeding foo and following Bar ensure that these matched characters are just between a foo
and a Bar
.
\(...\)
stores this characters so that they can be used in the replace part of the substitution.
&
copies what was matched
\1
is the string captured in the \(....\)
part.
You need to capture what you want to save. Try something like this:
%s/\(foo\(\w\+\)Bar\);/\1 = \2 \2Old/
Or you can clean it up a little bit with magic:
%s/\v(foo(\w+)Bar);/\1 = \2 \2Old/