feat(nvim): add keybind to toggle task state in markdown
All checks were successful
Check Formatting of Files / Check-Formatting (push) Successful in 1m16s

This commit is contained in:
Price Hiller 2024-05-12 12:07:22 -05:00
parent 15fce9a248
commit 20fc010630
Signed by: Price
GPG Key ID: C3FADDE7A8534BEB

View File

@ -6,3 +6,20 @@ vim.opt_local.wrap = false
vim.keymap.set("n", "<leader>fr", "<cmd>MarkdownPreview<CR>", {
buffer = true,
})
vim.keymap.set("n", "<C-Space>", function()
local cur_line = vim.fn.line(".")
local line_text = vim.fn.getline(".")
local lead, char, task = line_text:match("^(%s*- )%[(.)%](.*)")
local new_char
if char == " " then
new_char = "x"
elseif char == "x" then
new_char = " "
end
if new_char then
local updated_task_str = lead .. "[" .. new_char .. "]" .. task
vim.api.nvim_buf_set_lines(0, cur_line - 1, cur_line, true, { updated_task_str })
end
end, { buffer = true })