- Notifications
You must be signed in to change notification settings - Fork244
-
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 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. |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 1 comment
-
Thanks for sharing! 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'}) |
BetaWas this translation helpful?Give feedback.
All reactions
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment