Reputation: 1824
I've got a string:
doCall(valA, val.valB);
Using a regex in GVIM I would like to change this to:
valA = doCall(valA, val.valB);
How would I go about doing this? I use %s
for basic regex search and replace in GVIM, but this a bit different from my normal usages.
Thanks
Upvotes: 2
Views: 662
Reputation: 545528
You can use this:
%s/\vdoCall\(<(\w*)>,/\1 = doCall(\1,/
\v
enables “more magic” in regular expressions – not strictly necessary here but I usually use it to make the expressions simpler. <…>
matches word boundaries and the in-between part matches the first parameter and puts it in the first capture group. The replacement uses \1
to access that capture group and insert into the right two places.
Upvotes: 1