Better note creation and such

This commit is contained in:
Imbus 2024-11-10 23:54:10 +01:00
parent 3555e9dc0a
commit c048e460d4

View file

@ -90,7 +90,7 @@ return { -- Fuzzy Finder (files, lsp, etc)
end, { desc = '[/] Fuzzily search in current buffer' })
-- Vimwiki searches for notes in path specified by $NOTES environment variable
vim.keymap.set('n', '<leader>sv', function()
vim.keymap.set('n', '<leader>svv', function()
local notes_path = os.getenv 'NOTES'
if not notes_path then
error 'Please set the $NOTES environment variable'
@ -99,6 +99,36 @@ return { -- Fuzzy Finder (files, lsp, etc)
end
end, { desc = '[S]earch [V]imWiki' })
vim.keymap.set('n', '<leader>svn', function()
local notes_path = os.getenv 'NOTES'
if not notes_path then
error 'Please set the $NOTES environment variable'
return
end
local function prompt_for_filename()
local filename = vim.fn.input 'Enter note filename: '
if filename == '' then
error 'Filename cannot be empty'
end
return filename
end
local function open_or_create_note()
local filename = prompt_for_filename()
local file_path = notes_path .. '/' .. filename .. '.md'
if vim.fn.filereadable(file_path) == 0 then
vim.cmd('edit ' .. file_path)
print('Created new note: ' .. file_path)
else
vim.cmd('edit ' .. file_path)
print('Opened existing note: ' .. file_path)
end
end
open_or_create_note()
end, { desc = '[S]earch or [V]iew/Create Note' })
-- It's also possible to pass additional configuration options.
-- See `:help telescope.builtin.live_grep()` for information about particular keys
vim.keymap.set('n', '<leader>s/', function()