Grep time range and date calculation

Just a tiny post to share a command I use since a quite of time now to grep time ranges, notably the things to do over 7 days.

:grep %sh(p today .. 7 days | cr 'todo.+%F' -j '|')

p is an alias to echo and cr to chronic.

The search output will look something like:


With the following document, it will match the “today” and “in 7 days” occurrences, but not “yesterday” and “in 14 days”.

TODO 2020-11-19 Something (Yesterday)
TODO 2020-11-20 Something (Today)
TODO 2020-11-27 Something (in 7 days)
TODO 2020-12-04 Something (in 14 days)

If you want something else than days you can configure the range step in days (-d), hours (-h), minutes (-m) and seconds (-s).

You can also do some maths, such as:

p today + 14 days | cr
# 2020-11-27 17:03:05

Which is quite useful if you want to search dates from the prompt.

/%sh(cr -i 'next monday' '%F')<a-!><ret>

Note: <a-!> is to expand typed expansions (here a shell block).

With 2020-12-04 selected:

TODO [2020-12-04] Something (in 14 days)


/%sh(cr -i "$kak_selection + 7 days" '%F')<a-!><ret>

will jump to 2020-12-11.

In the -i option, you have %s available if you need to map stdin.


p 2020-12-25 | cr -i '%s + tomorrow' '%F'
# 2020-12-26

In Kakoune, you can select dates and map them to other formats.

For example, select:

Oct 8, 2020


|cr '%F'

will result 2020-10-08.

1 Like