Skip to content

obsidian-nvim/nldates.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.0
  • Node.js >= 18
  • npm

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

  1. Install Node.js >= 18
  2. Install the neovim npm package: npm install -g neovim
  3. Run :checkhealth provider in 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"

About

natural language dates for neovim

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors