Sunday, May 19, 2013

How to do math in vim ?

Hi,

Can you do math in Vim?
Can you do subtractions?

I have a srt file where I want to subtract 7 from all the seconds in the file.
So this:
+------------------------------------+
24
00:07:55,641 --> 00:07:58,393
You can't do that to us!
We'll tell you a secret.

25
00:07:58,603 --> 00:07:59,769
A secret? Who by?
+------------------------------------+


becomes:
+------------------------------------+
24
00:07:48,641 --> 00:07:51,393
You can't do that to us!
We'll tell you a secret.

25
00:07:51,603 --> 00:07:52,769
A secret? Who by?
+------------------------------------+
The changes in this are:
(55 becomes 48)
(58 becomes 51)
(59 becomes 52)


Meaning:
- search for the lines with -->
- search for the number before the first , (comma)
- subtract that number with 7
- search for the number before the second , (comma)
- subtract that number with 7


I don't know if vim can subtract it also to negative numbers?
In case you have this:
+------------------------------------+
27
00:08:01,898 --> 00:08:04,316
She's visiting--

28
00:08:04,525 --> 00:08:07,277
Who wants to know about her?
+------------------------------------+

becomes:
+------------------------------------+
27
00:08:-06,898 --> 00:08:-03,316
She's visiting--

28
00:08:-03,525 --> 00:08:00,277
Who wants to know about her?
+------------------------------------+
The changes in this are:
(01 becomes -06)
(04 becomes -03)
(07 becomes 00)

Although not correct for srt syntax, these are manual fixable .

Rgds,
Jeri


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
 
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment