Add :CheckboxToggle and mapping
This commit is contained in:
parent
8a5f4a3063
commit
8b4258408e
@ -150,3 +150,18 @@ vim.api.nvim_create_user_command('PreProcIfWrap', function(opts)
|
|||||||
local window = vim.api.nvim_get_current_win()
|
local window = vim.api.nvim_get_current_win()
|
||||||
vim.api.nvim_win_set_cursor(window, { opts.line1, 5 })
|
vim.api.nvim_win_set_cursor(window, { opts.line1, 5 })
|
||||||
end, { range = true })
|
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, {})
|
||||||
|
@ -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
|
-- 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('n', '<leader>rg', ':Rg<CR>', opts)
|
||||||
vim.keymap.set('v', '<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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user