use vim script to let all time stamp in a srt text file increase or decrease

StackOverflow https://stackoverflow.com/questions/19074652

  •  29-06-2022
  •  | 
  •  

Pregunta

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

......
¿Fue útil?

Solución 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.

Otros consejos

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).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top