mirror of
https://github.com/obsidian-nvim/nldates.nvim.git
synced 2026-11-17 02:50:28 +00:00
natural language dates for neovim
- Lua 89.5%
- JavaScript 10.5%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| lua | ||
| rplugin/node/nldates | ||
| .gitignore | ||
| LICENSE | ||
| package-lock.json | ||
| README.md | ||
nldates.nvim
Natural language dates for Neovim. Parse date strings like "next Friday", "tomorrow", or "2 weeks ago" into formatted dates.
Features
- Parse natural language dates using chrono-node
- Format dates with moment.js
- Visual mode integration - select text and transform in place
Requirements
Neovim>= 0.9.0Node.js>= 18npm
Run :checkhealth provider in Neovim to verify your Node provider is working.
Installation
Lazy.nvim
return {
"obsidian-nvim/nldates.nvim",
build = function()
if not vim.g.node_host_prog then
vim.g.node_host_prog = vim.fn.exepath("neovim-node-host")
end
vim.fn.jobstart("cd rplugin/node/nldates; npm install")
vim.cmd("UpdateRemotePlugins")
end,
}
Manual npm Installation
cd ~/.local/share/nvim/lazy/nldates.nvim/rplugin/node/nldates
npm install
Restart Neovim after installation.
Node Provider Setup
- Install Node.js >= 18
- Install the neovim npm package:
npm install -g neovim - Run
:checkhealth providerin Neovim to verify
Usage
Select a date string in visual mode and run:
:'<,'>lua require("nldates").replace_selection()
Keybinding
Replace date
vim.keymap.set("v", "<leader>nd", function()
require("nldates").replace_selection()
end)
Select next friday and press gd → becomes 2025-02-21
Format with moment.js
See https://momentjs.com/docs/#/displaying/format/ for full reference.
vim.keymap.set("v", "<leader>nd", function()
require("nldates").replace_selection({ format = "[[][[]YYYY-MM-DD[]][]]" })
end)
Select next friday and press gd → becomes 2025-02-21
API
require("nldates").replace_selection(opts?)
Parses the visual selection as a natural language date and replaces it.
Options:
format(string): Output format. Default:"YYYY-MM-DD"
Supported Date Formats
- Relative: "tomorrow", "next week", "2 days ago"
- Specific: "January 15th", "2025-01-15"
- Day names: "next friday", "last monday"
- Time: "at 3pm", "tomorrow morning"