From 20fc010630af01e347d4d2492933cec77e54fd72 Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Sun, 12 May 2024 12:07:22 -0500 Subject: [PATCH] feat(nvim): add keybind to toggle task state in markdown --- .../.config/nvim/after/ftplugin/markdown.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/users/price/dots/.config/nvim/after/ftplugin/markdown.lua b/users/price/dots/.config/nvim/after/ftplugin/markdown.lua index 70f1ff1d..2816d895 100644 --- a/users/price/dots/.config/nvim/after/ftplugin/markdown.lua +++ b/users/price/dots/.config/nvim/after/ftplugin/markdown.lua @@ -6,3 +6,20 @@ vim.opt_local.wrap = false vim.keymap.set("n", "fr", "MarkdownPreview", { buffer = true, }) + +vim.keymap.set("n", "", 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 })