PDA

View Full Version : Vim How to increase a value in search replace command



ivancp
March 29th, 2011, 01:32 AM
Hello,

I have this text in a source file:


/* Script: A script
* Author: xyz
* Date-created: 28 mar 2011 18:47:07
* Last-modified: 28 mar 2011 18:47:19
* Revision: 12
*/I want to update the Revision line when I save the file,
I have this search-replace command

s/\(Revision:\) \(\.*\)/\1 \2/g

How to increment the value of \2 match?

From: Revision: 12
To: Revision: 13

Regards.

lloyd_b
March 30th, 2011, 06:59 AM
Try this one:
s/Revision: \zs\d\+/\=submatch(0) + 1/It will search for "Revision: " followed by an integer value, replacing it with "Revision: " and the integer value plus one.

Lloyd B.

ivancp
April 10th, 2011, 07:13 PM
Thank you!

geirha
April 11th, 2011, 08:20 AM
Why not use a VCS that can do that for you?