Question

for example: how to let time stamp all minus 1,thanks :)

part of a srt text file:

1
00:00:04,110 --> 00:00:08,409 
hi my name's mike

......

and I want to let it be:

1
00:00:03,110 --> 00:00:07,409 
hi my name's mike

......
Was it helpful?

Solution 2

You can use vim's regular expressions to get what you want:

:%s;\(\d\{2}\)\(,\d\{3}\);\=printf("%02d%s", submatch(1) - 1, submatch(2));g

:           - begin command line mode.
%           - entire file.
s           - substitute.
;           - field separator.
\(          - begin sub-expression.
\d          - match digit.
\{2)        - match exactly two.
\)          - end sub-expression.
,           - actual comma.
\{3)        - match exactly three.
printf()    - internal vim function (see :h printf).
submatch(1) - match first sub-expression.
submatch(2) - match second sub-expression.
g           - replace all occurrences in the line.

OTHER TIPS

The speeddating.vim plugin (https://github.com/tpope/vim-speeddating) allows you use vim's CTRL-A/CTRL-X increment/decrement keys to work with dates and times in many formats.

Simply install it then go to the seconds column in the srt file and press CTRL-X. Speeddating understands that 23:23:00 becomes 23:22:59 and 23:00:00 becomes 22:59:59.

You can then "automate" changes with a "g command" like:

:g/\v^\d{2}:\d{2}:/execute "normal t,10\<C-x>2t,10\<C-x>"

to change start and end of sequence down 10 seconds.

The t, and 2t, take you to the first and second comma in the line putting you on the seconds column. 2t: and 3t: would put you on the minutes and so on, or use whichever motion commands you prefer (7l 17l for seconds maybe).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top