diff --git a/nvim/.config/nvim/after/ftplugin/markdown.lua b/nvim/.config/nvim/after/ftplugin/markdown.lua index c52ab63..4fee4ae 100644 --- a/nvim/.config/nvim/after/ftplugin/markdown.lua +++ b/nvim/.config/nvim/after/ftplugin/markdown.lua @@ -11,18 +11,28 @@ if require("core.util").is_available("which-key") then }) end --- add tasks w/ -map({ "i" }, "", function() - local line = vim.api.nvim_get_current_line() +-- Toggles existence of a md checkbox (`- [ ] `) on current line +-- Can be used on list lines, non-list lines or existing checkbox +local function toggle_checkbox() 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) + local line = vim.api.nvim_get_current_line() + local updated_line + -- look for existing checkbox + if line:find("^%s*[-*]%s%[[%sxo]%]") then + updated_line = line:gsub("^(%s*)([-*]?)%s*%[[%sxo-~]%]", "%1%2", 1) + -- look for existing list dash/asterisk + elseif line:find("^%s*[-*]%s") then + updated_line = line:gsub("^(%s*)([-*])%s*", "%1%2 [ ] ", 1) + -- add to non-list line + else + updated_line = line:gsub("^(%s*)", "%1- [ ] ", 1) + end 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) +end + +-- add tasks w/ +map({ "n", "i" }, "", toggle_checkbox) if require("core.util").is_available("zk") and require("zk.util").notebook_root(vim.fn.expand("%:p")) ~= nil then map("n", "", "lua vim.lsp.buf.definition()", { silent = true }) diff --git a/nvim/.config/nvim/lua/plugins/pickers.lua b/nvim/.config/nvim/lua/plugins/pickers.lua index 98e2625..05db98c 100644 --- a/nvim/.config/nvim/lua/plugins/pickers.lua +++ b/nvim/.config/nvim/lua/plugins/pickers.lua @@ -191,7 +191,7 @@ return { -- file/item pickers and managers desc = "path complete", }, { - "", + "", function() require("fzf-lua").complete_path() end,