A nvim-cmp source for turning natural dates into ISO dates.
2023-10-13.13-05-51.mp4
@now->2023-10-13 12:38@tomorrow->2023-10-14@last Friday 2pm->2023-10-06 14:00@Oct 8 2021->2021-10-08@today 14:20->2023-10-13 14:20
- autocomplete for partially typed month names, relative dates
- supported formats:
nowyesterday,today,tomorrowwith optional time- days of week (Monday -> Sunday), with optional
last/nextmodifier and time - full dates: month, day, optional year, optional time
- time: am/pm, or 24h format
-
Install the plugin
Using lazy.nvim:
{ "Gelio/cmp-natdat", config = true }config = trueis necessary so lazy.nvim callsrequire("cmp_natdat").setup()to register the source.Using packer.nvim:
use { "Gelio/cmp-natdat", config = function() require("cmp_natdat").setup() end }
-
Add the source to the list in your nvim-cmp configuration
sources = { { name = "natdat" }, --- other sources... }
cmp-natdat accepts the following optional configuration, passed as a table to
the setup() method:
-
cmp_kind_text- the text to use as the completion item's label in the nvim-cmp completions popup.Default:
Text -
highlight_group- the name of an existing highlight group to use for that completion item's label in the nvim-cmp completions popup.Default:
CmpItemKindText
Example:
{
"Gelio/cmp-natdat",
config = function()
require("cmp_natdat").setup({
cmp_kind_text = "NatDat",
highlight_group = "Red",
})
end,
}To get the most out of the custom cmp kind text, you can also use lspkind.nvim to show the calendar icon (📆) for cmp-natdat completions:
require("lspkind").init({
symbol_map = {
NatDat = "📅",
},
})Parsing the dates is done using pcomb, a Lua parser combinator library. Its API is inspired by Rust's nom crate.
pcomb can also be used in other plugins to parse other text input into a more
structured format. It is flexible and makes it easy to build parsers from the
bottom-up:
---@type pcomb.Parser<{ [1]: integer, [2]: pcomb.NIL | integer }>
local day_of_month_and_opt_year = psequence.sequence({
-- Day of month
pcharacter.integer,
pcombinator.opt(psequence.preceded(
pcharacter.multispace1,
-- Year
pcharacter.integer,
))
})See CONTRIBUTING.md.

