Re: calculations on result from search
> I have several files where I need to make some substitutions. In one ofthis
> substitutions I need to make a calculation on a result from a search.subtract
> For example, I have a column like this:
> I want to change only the lines that end with 00; on this lines I need to
> 1 from the number on left side of :. So, the result should be:How does this work for you?
'^0*','','g')-1), '.*\(..\)', '\1', '').':00'
It's ugly, but it accomodates the wrinkle that vim considers leading zeros
an indicator of an octal number, which does funky stuff with the maths at
hand. So, it strips off the leading zero, decrements, tacks a leading zero
back onto it, and then pulls the two right-most characters. It doesn't
monkey with "00:00" any differently (you get a negative number--which may or
may not be the desired behavior)
Hope this helps,
- Luis Marcelo de Mattos Zeri wrote:
>I want to change only the lines that end with 00; on this lines I need to subtractI'll try again!
>1 from the number on left side of :. So, the result should be:
I'm sure there's a better way (ie writing a function to catch inevitable
errors) but this seems to work as you'd expect ( except for those errors
I'm talking about ;-))
whats it mean?
@ is the separator ie :%s@this@that@
\( \) are for grouping
^ find the start of the line
\d followed by a digit
\zs now that you've found it, forget about it & start the actual
\d find a digit (the one you want to change)
\ze:00 find :00 ie it must be present, but dont include it
\= evaluate the replacement bit as an expression
submatch(2)-1 better just to point to :h submatch
Problem (if this relates to times):
it will turn a 0 into -1 so :00 becomes :0-1 NOT :59
which wouldn't be what you need.
Far better to write a script.
- Thank you Roberto, Klaus, Mark and Trevor!
All the solutions worked very well.
> On Sun, 2 May 2004, Luis Marcelo de Mattos Zeri wrote:
>> I have several files where I need to make some substitutions. In one
>> of this substitutions I need to make a calculation on a result from
>> a search. For example, I have a column like this:
>> I want to change only the lines that end with 00; on this lines I need
>> to subtract 1 from the number on left side of :.
> :g/00$/ exe "norm! 0\<C-X>"