I'm new to Vim and I'm trying to see what I can / can't do with it. I would like to increment a list of times like this :
09:00 Breakfast
09:30 RSS
09:50 Stretch
10:00 Main proj
13:00 food
14:00 Main proj...
Lets say I woke up too late, and I'd like to quickly increment everything by 45 minutes in Vim
I tried a macro :
- Time in minutes :
09:00 -> 09 * 60 + 00
+ 45
- SUM with Ctrl + R =
- Trying to reformat it
(int)SUM/60 : SUM - ((int)SUM/60)*60
But I couldn't get it to work (it is such a long macro) and I'm quicker at doing it manually.
On top of that, even if I succeed I can't figure out how to keep the "0"
of "09"
to keep my numbers in a column.
Is it possible in Vim ? Maybe a regex ?
[edit] For the purpose of exercise, I'd rather use macros, a regex, or even a function in VimScript than a plugin
So, I tried in a regex ( remove return carriage) :
it's quite inelegant and i'd like to have
inc = 45
andsum = (submatch(1)*60+submatch(2)+inc)
, I would need to declare the variables on the same line as the printf... but it works ;)Inside visual selection : with
'<,'>
instead of%
.One problem of course is that it doesnt loop back around midnight, but I guess for that @steffen's answer would be better
Edit : I found that modulo existed in Vimscript and I couldn't resist...now it loops around midnight :
Edit 2: And here is the code in a function using the func-range (thanks @Kent)
I had to add 1440 to avoid negative hours when one decrements