diff --git a/init.lua b/init.lua index e8cd132..5c440f5 100644 --- a/init.lua +++ b/init.lua @@ -826,6 +826,24 @@ vim.api.nvim_create_autocmd('BufEnter', { vim.opt_local.formatoptions:append("t") end, }) +local function toggle_checkbox() + local line = vim.api.nvim_get_current_line() + local new + if line:match('%[ %]') then + new = line:gsub('%[ %]', '[x]', 1) + elseif line:match('%[x%]') then + new = line:gsub('%[x%]', '[ ]', 1) + elseif line:match('^(%s*[-*+])%s+(.*)') then + -- bare list item → promote to checkbox + new = line:gsub('^(%s*[-*+])%s+', '%1 [ ] ', 1) + else + return + end + vim.api.nvim_set_current_line(new) +end + +vim.keymap.set('n', 'tc', toggle_checkbox, + { desc = 'Toggle markdown checkbox', buffer = false }) ------------------------------------------------------------------------------- -- Comments