1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
local function toggle_todo()
local ln, n = vim.api.nvim_get_current_line(), 0
ln, n = string.gsub(ln, 'TODO', 'DONE', 1)
if n > 0 then
goto set_line
end
ln, n = string.gsub(ln, 'DONE', 'TODO', 1)
if n > 0 then
goto set_line
end
ln, n = string.gsub(ln, '^(-|*) ', '%1 TODO ')
if n > 0 then
goto set_line
end
goto exit -- skip over set_current_line
::set_line::
vim.api.nvim_set_current_line(ln)
::exit::
end
vim.keymap.set('n', '<space><space>', toggle_todo, { desc = 'toggle todo', buffer = true })
|