nvim: Add mapping to insert todo item into markdown

Use <C-x> when in insert mode and it will prepend the line with an empty
todo item.
This commit is contained in:
Marty Oehme 2025-07-16 17:34:49 +02:00
parent 27ef79391c
commit c26ef032d2
Signed by: Marty
GPG key ID: 4E535BC19C61886E

View file

@ -11,6 +11,19 @@ if require("core.util").is_available("which-key") then
})
end
-- add tasks w/ <C-x>
map({ "i" }, "<C-x>", function()
local line = vim.api.nvim_get_current_line()
local cursor = vim.api.nvim_win_get_cursor(0)
-- remove existing prefixes if any
-- TODO: Improved matching for e.g. '- [ ]' already on line, or indented '-'
-- and add task on line below if line is already populated
local updated_line = line:gsub("^%s*[-*]%s*", "", 1)
vim.api.nvim_set_current_line(updated_line)
vim.api.nvim_win_set_cursor(0, { cursor[1], #updated_line })
vim.api.nvim_put({ "- [ ] " }, "c", true, true)
end)
if require("core.util").is_available("zk") and require("zk.util").notebook_root(vim.fn.expand("%:p")) ~= nil then
map("n", "<CR>", "<cmd>lua vim.lsp.buf.definition()<cr>", { silent = true })
end