Add constant value to numeric XML attribute
- by Dave Jarvis
Background
Add a constant value to numbers matched with a regular expression, using vim (gvim).
Problem
The following regular expression will match width="32":
/width="\([0-9]\{2\}\)"
Question
How do you replace the numeric value of the width attribute with the results from a mathematical expression that uses the attribute's value? For example, I would like to perform the following global replacement:
:%s/width="\([0-9]\{2\}\)"/width="\1+10"/g
That would produce width="42" for width="32" and width="105" for width="95".
Thank you!