Extract and use part of a string with regex in GVIM

I have a line:

doCall(valA, val.valB);

      

Using regex in GVIM, I would like to change this to:

valA = doCall(valA, val.valB);

      

How can I do it? I use it %s

for regular regex search and replace in GVIM, but it's a little different from my usual usage.

thanks

+2


a source to share


1 answer


You can use this:

%s/\vdoCall\(<(\w*)>,/\1 = doCall(\1,/

      



\v

allows "more magic" in regular expressions - not necessary here, but I usually use it to simplify expressions. <…>

matches the word boundaries and the intermediate matches the first parameter and puts it in the first capture group. Replacement uses \1

grab and paste to access this group at the correct two locations.

+1


a source







All Articles