I have several lines similar to this this:
insert into team (lowernum, uppernum, position, color1, color2) values (15, 16, 32, "red", "green");
I want to perform a search and replace in vim to change the third number (108 in this example) on every line so that it is increased by 15. The resultant line therefore will look like this:
insert into team (lowernum, uppernum, position, color1, color2) values (15, 16, 47, "red", "green");
I have tried several search and replace options, but have not figured out how to combined variables with submatches to get my desired result. An example of what I have tried is here:
:%s/\((\d\d, \d\d, \)\(\d\d\)/\=\1 submatch(2) + 15/g
Obviously, this gives an error, but I haven't been able to figure out the correct way to implement the replace clause. What is the correct way to do this?
Answer
Based on romainl's answer, this is the solution that worked for me:
:%s/\d\{1,}, \d\{1,}, \zs\(\d\{1,}\)/\=submatch(0) + 15/g
zs indicates the start of the pattern that will be replaced.
UPDATE team SET position = position + 15;