dotfiles

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

commit b213f805e131579b9b0c28fc52a6cbaf38dfccb8
parent 8efada52e7ecad0292423c654d3972e05a5c617d
Author: Chris Bracken <chris@bracken.jp>
Date:   Mon, 13 Jul 2026 06:38:40 +0900

nvim: use weekly notes instead of daily ones

Daily notes is too fine-grained; usually I want context from the last
couple days. I feel like I probably did made this same change in vimwiki
a long time ago too :/

Update utils.jump_daily() to organize notes by week starting on Monday
instead of to individual days. Pressing <leader>dd now opens
notes/yyyy/yyyy-mm-dd.md where yyyy-mm-dd is the Monday for the current
week. <leader>dp and <leader>dn (jump to prev/next) are also updated.

Diffstat:
M.config/nvim/lua/config/keymaps.lua | 12++++++------
M.config/nvim/lua/custom/utils.lua | 41+++++++++++++++++++++++++++++------------
2 files changed, 35 insertions(+), 18 deletions(-)

diff --git a/.config/nvim/lua/config/keymaps.lua b/.config/nvim/lua/config/keymaps.lua @@ -110,20 +110,20 @@ vim.keymap.set('n', '<leader>n', function() end end) --- Open today's daily note. +-- Open current week's note. vim.keymap.set('n', '<leader>dd', function() utils.jump_daily(0) -end, { desc = "Open today's daily note", noremap = true, silent = true }) +end, { desc = "Open current week's note", noremap = true, silent = true }) --- Go to previous day's note relative to current note (or today). +-- Go to previous week's note relative to current note (or current week). vim.keymap.set('n', '<leader>dp', function() utils.jump_daily(-1) -end, { desc = "Go to previous daily note", noremap = true, silent = true }) +end, { desc = "Go to previous weekly note", noremap = true, silent = true }) --- Go to next day's note relative to current note (or today). +-- Go to next week's note relative to current note (or current week). vim.keymap.set('n', '<leader>dn', function() utils.jump_daily(1) -end, { desc = "Go to next daily note", noremap = true, silent = true }) +end, { desc = "Go to next weekly note", noremap = true, silent = true }) -- Open tasks vim.keymap.set('n', '<leader>dt', function() diff --git a/.config/nvim/lua/custom/utils.lua b/.config/nvim/lua/custom/utils.lua @@ -19,6 +19,16 @@ function M.change_google3_subdir(subdir) end end +local function get_monday_time(time_table) + local d = os.date("*t", os.time(time_table)) + local days_to_monday = (d.wday - 2 + 7) % 7 + return os.time({ + year = d.year, + month = d.month, + day = d.day - days_to_monday, + }) +end + function M.jump_daily(offset) local notes_dir = vim.g.notes_dir assert(notes_dir, "vim.g.notes_dir is not set") @@ -29,28 +39,35 @@ function M.jump_daily(offset) local target_time if offset == 0 then - -- Jump to today. - target_time = os.time() + -- Jump to current week's Monday (based on today). + target_time = get_monday_time(os.date("*t")) elseif year and month and day then - -- Offset relative to note date. - target_time = os.time({ + -- Offset relative to current note's Monday. + local monday_time = get_monday_time({ year = tonumber(year), month = tonumber(month), - day = tonumber(day) + offset, + day = tonumber(day), + }) + local monday_date = os.date("*t", monday_time) + target_time = os.time({ + year = monday_date.year, + month = monday_date.month, + day = monday_date.day + (offset * 7), }) else - -- Unable to resolve note date; offset relative to today. - local today = os.date("*t") + -- Unable to resolve note date; offset relative to current week's Monday. + local monday_time = get_monday_time(os.date("*t")) + local monday_date = os.date("*t", monday_time) target_time = os.time({ - year = today.year, - month = today.month, - day = today.day + offset, + year = monday_date.year, + month = monday_date.month, + day = monday_date.day + (offset * 7), }) end local target_date = os.date("*t", target_time) - 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 formatted_date = string.format("%04d/%04d-%02d-%02d", + target_date.year, target_date.year, target_date.month, target_date.day) local expanded_dir = vim.fn.expand(notes_dir) local path = vim.fs.joinpath(expanded_dir, formatted_date .. ".md")