I have this text with numbers:
My numbers are 04, and 0005
My numbers are 05, and 0006
My numbers are 06, and 0035
My numbers are 07, and 0007
My numbers are 08, and 0009
This is the code I always used to increment or decrement numbers in a selection/block selection/column: p.e. increment the last 4 numbers in above text with 8:
'<,'>s/\%V\<\d\{4}\>/\=submatch(0)+8/g
but I noted today that it does strange things. This is the output:
My numbers are 04, and 13
My numbers are 05, and 14
My numbers are 06, and 37 <---
My numbers are 07, and 15
My numbers are 08, and 17
Can anyone help me to find a regex to add /subtract numbers from selection (or block selection) without losing the leading zero's?
note:
I noted that Control A + Control x keeps the leading zero's and does the work as I want but:
- I've seen that it can not be used in a substitute command ('<,'>s/)
- and I don't know how to add p.e. 200 to a list of numbers (200 x ?)
leading zero makes number 8-based
.
(0035)8 == (29)10
You can test in vim:
:echo 0035 == 29
It'll print 1
(true).
Try this:
:%s/\(\<[0-9]\{4}\>\)\@=0*\([0-9]*\)/\=submatch(2)+8/