0

I would like to create a simple pomodoro timer I can insert into text files. Something like:

Current Time - 10:15

End Time - 10:40

However I have not been able to find a good way to insert a future time.

I have used :put =strftime('%T') to create the current time and this works perfectly, however I am not sure how to "add" to this time to create a t + 25m time.

2

You can get the current time with localtime():

:echo localtime()
1611790246

And you can format this with strftime() by passing it as the second argument:

:echo strftime('%T', localtime())
07:32:16

And you can modify it as well:

:echo strftime('%T', localtime() + 60 * 25)
07:57:16

So for your command it'll be something like:

:put =strftime('%T', localtime() + 60 * 25)

In reality, you probably want to save the localtime() and then insert strftime('%T', time) and strftime('%T', time + 60 * 25), because otherwise you might risk the time between the two operations being just long enough for it to be off by one second/minute. You can also round it to 25-minute intervals with some more math.

See :help localtime() and :help strftime() for more information on all of the above. :help function-list is also very useful, which includes a "date and time" section. Also see How do I navigate to topics in Vim's documentation?

0

If you don't mind using a system based solution, then on ubuntu (and many linuxes)

date --date="5 mins"

returns the current time + 5 minutes. You can also ask for hours, days, even "next monday" will give you the date of the next monday. To load these values into a vim buffer use the 'read from command' command:

:r! date
:r! date --date="5 mins"
1
  • Unfortunately I am on windows, I have tried a few variants of the windows command time/T but I couldn't get the same behavior. Jan 25 at 19:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.