Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Previous/Next daily note based on currently open note#498

zDonik1 started this conversation inCookbook
Discussion options

I have added 2 of my own commands that switch to the previous/next daily note based on the currently open note in buffer.

The only issue is that there is no support for custom date formats, so the commands only work on filename dates with the default%Y-%m-%d format.

localoffset_daily=function(offset)localfilename=vim.fn.expand("%:t:r")localyear,month,day=filename:match("(%d+)-(%d+)-(%d+)")localdate=os.time({year=year,month=month,day=day })localclient=require("obsidian").get_client()localnote=client:_daily(date+ (offset*3600*24))client:open_note(note)endvim.api.nvim_create_user_command("ObsidianPrevDay",function(_)offset_daily(-1)end, {bang=false,bar=false,register=false,desc="Create and switch to the previous daily note based on current buffer",})vim.api.nvim_create_user_command("ObsidianNextDay",function(_)offset_daily(1)end, {bang=false,bar=false,register=false,desc="Create and switch to the next daily note based on current buffer",})

A PR could be started if custom date parsing is implemented.

You must be logged in to vote

Replies: 1 comment

Comment options

Thanks for sharing!
Below are my mappings based on the same idea for navigating to the next/previous existing daily note.

localfunctionnext_daily(step)localbuf_path=vim.api.nvim_buf_get_name(0)ifnotbuf_pathorbuf_path==''thenvim.notify('buffer has no path',vim.log.levels.INFO)returnendlocalbuf_dir=vim.fn.fnamemodify(buf_path,':p:h')localjournal_dir=vim.fn.fnamemodify('~/notes/daily',':p:h')ifbuf_dir~=journal_dirthenvim.notify('not a daily buffer',vim.log.levels.INFO)returnendlocalbuf_file=vim.fn.fnamemodify(buf_path,':t:r')localyear,month,day=buf_file:match('(%d+)%-(%d+)%-(%d+)')ifnotyearornotmonthornotdaythenvim.notify('unexpected daily file format:'..buf_path,vim.log.levels.INFO)returnendlocalcurr_date=os.time({year=year,month=month,day=day })fori=1,30do-- only look for files within a monthlocalnext_date=os.date('%Y-%m-%d',curr_date+i*step*24*3600)localnext_file=journal_dir..'/'..next_date..'.md'ifvim.loop.fs_stat(next_file)thenvim.cmd('edit'..next_file)returnendendvim.notify('no more close daily files',vim.log.levels.INFO)endvim.keymap.set('n','<leader>j;',function()next_daily(1)end, {desc='Open next daily file'})vim.keymap.set('n','<leader>j,',function()next_daily(-1)end, {desc='Open previous daily file'})
You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Labels
None yet
2 participants
@zDonik1@raindev

[8]ページ先頭

©2009-2025 Movatter.jp