Add :CheckboxToggle and mapping

This commit is contained in:
Kenneth Benzie 2024-07-11 20:09:43 +01:00
parent 8a5f4a3063
commit 8b4258408e
2 changed files with 18 additions and 0 deletions

View File

@ -150,3 +150,18 @@ vim.api.nvim_create_user_command('PreProcIfWrap', function(opts)
local window = vim.api.nvim_get_current_win()
vim.api.nvim_win_set_cursor(window, { opts.line1, 5 })
end, { range = true })
vim.api.nvim_create_user_command('CheckboxToggle', function(opts)
local linenr = vim.fn.line('.')
local line = vim.fn.getline(linenr)
local pos = string.find(line, '[ ]', 0, true)
if pos == nil then
pos = string.find(line, '[x]', 0, true)
if pos == nil then
return
end
end
local x = string.sub(line, pos + 1, pos + 1)
if x == 'x' then x = ' ' else x = 'x' end
vim.fn.setline(linenr, string.sub(line, 1, pos) .. x .. string.sub(line, pos + 2))
end, {})

View File

@ -47,3 +47,6 @@ vim.keymap.set('t', '<C-w><C-a>', '<C-\\><C-n>:Asm<CR>', opts)
-- Mappings to grep for then fuzzy find the word under the cursor or visual selection
vim.keymap.set('n', '<leader>rg', ':Rg<CR>', opts)
vim.keymap.set('v', '<leader>rg', ":'<,'>Rg<CR>", opts)
-- Mapping to toggle checkboxes
vim.keymap.set('n', '<leader><CR>', ':CheckboxToggle<CR>', opts)