dotfiles

Personal dotfiles
git clone https://git.bracken.jp/dotfiles.git
Log | Files | Refs | LICENSE

commit cbd468785a4f57d6174a2f1026704485b1b1fee7
parent ad82542ebd2047f588728d3cd419cca3fff1b99f
Author: Chris Bracken <chris@bracken.jp>
Date:   Fri,  5 Jun 2026 18:55:36 +0900

nvim: add mappings for markdown-oxide daily notes

Adds the following mappings:

* <leader>dd: open daily note for today
* <leader>dp: open previous day's daily note
* <leader>dn: open next day's daily note

Diffstat:
M.config/nvim/lua/config/keymaps.lua | 26+++++++++++++++-----------
M.config/nvim/lua/custom/utils.lua | 36++++++++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+), 11 deletions(-)

diff --git a/.config/nvim/lua/config/keymaps.lua b/.config/nvim/lua/config/keymaps.lua @@ -1,3 +1,5 @@ +local utils = require('custom.utils') + -- Globals. vim.g.mapleader=' ' -- Set <leader> key. @@ -102,16 +104,18 @@ vim.keymap.set('n', '<leader>n', function() end end) --- Open today's daily note unconditionally. -vim.keymap.set('n', '<leader>dn', function() - if vim.fn.exists(':Daily') == 2 then - vim.cmd('Daily') - else - local notes_dir = vim.g.notes_dir - assert(notes_dir, "vim.g.notes_dir is not set") - local today = os.date("%Y/%m/%Y-%m-%d") - local path = vim.fn.expand(notes_dir .. "/" .. today .. ".md") - vim.cmd("edit " .. vim.fn.fnameescape(path)) - end +-- Open today's daily note. +vim.keymap.set('n', '<leader>dd', function() + utils.jump_daily(0) end, { desc = "Open today's daily note", noremap = true, silent = true }) +-- Go to previous day's note relative to current note (or today). +vim.keymap.set('n', '<leader>dp', function() + utils.jump_daily(-1) +end, { desc = "Go to previous daily note", noremap = true, silent = true }) + +-- Go to next day's note relative to current note (or today). +vim.keymap.set('n', '<leader>dn', function() + utils.jump_daily(1) +end, { desc = "Go to next daily note", noremap = true, silent = true }) + diff --git a/.config/nvim/lua/custom/utils.lua b/.config/nvim/lua/custom/utils.lua @@ -19,4 +19,40 @@ function M.change_google3_subdir(subdir) end end +function M.jump_daily(offset) + local notes_dir = vim.g.notes_dir + assert(notes_dir, "vim.g.notes_dir is not set") + + local current_file = vim.api.nvim_buf_get_name(0) + local year, month, day = current_file:match("(%d%d%d%d)%-(%d%d)%-(%d%d)%.md$") + + local target_date + if year and month and day then + local current_time = os.time({ + year = tonumber(year), + month = tonumber(month), + day = tonumber(day), + hour = 12 + }) + local target_time = current_time + (offset * 86400) + target_date = os.date("*t", target_time) + else + local target_time = os.time() + (offset * 86400) + target_date = os.date("*t", target_time) + end + + local formatted_date = string.format("%04d/%02d/%04d-%02d-%02d", + target_date.year, target_date.month, target_date.year, target_date.month, target_date.day) + + local path = vim.fn.expand(notes_dir .. "/" .. formatted_date .. ".md") + + -- Create parent directories if they don't exist + local dir = vim.fn.fnamemodify(path, ":h") + if vim.fn.isdirectory(dir) == 0 then + vim.fn.mkdir(dir, "p") + end + + vim.cmd("edit " .. vim.fn.fnameescape(path)) +end + return M