dotfiles

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

snippets.lua (598B)


      1 -- Function to get the current date in 'YYYY-mm-dd (Day)' format
      2 local function get_current_date()
      3   local fname = vim.fn.expand('%:t:r')
      4   local date_pattern = '^%d%d%d%d%-%d%d%-%d%d$'
      5   
      6   if fname:match(date_pattern) then
      7     local fdate = vim.fn.strptime('%Y-%m-%d', fname)
      8     return vim.fn.strftime('%Y-%m-%d (%a)', fdate)
      9   else
     10     return vim.fn.strftime('%Y-%m-%d (%a)')
     11   end
     12 end
     13 
     14 -- Key mapping to insert the current date in 'YYYY-mm-dd (Day)' format
     15 vim.keymap.set('n', '<Leader>cd', function()
     16   local date_str = get_current_date()
     17   vim.api.nvim_put({date_str}, 'c', true, true)
     18 end)