summary refs log tree commit diff
path: root/.vim/after/ftplugin/todofile.lua
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2024-05-15 09:00:31 +0200
committerRobert Günzler <r@gnzler.io>2024-05-15 09:00:31 +0200
commit3dbe74f2eef627e2dc19b79fe06753d5dc09003f (patch)
treeb78d1cdab62cec9ed4bbe35447108547b935ef03 /.vim/after/ftplugin/todofile.lua
parent0ab72c1113139c196115c974eadaded449002c32 (diff)
update nvim
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to '.vim/after/ftplugin/todofile.lua')
-rw-r--r--.vim/after/ftplugin/todofile.lua23
1 files changed, 23 insertions, 0 deletions
diff --git a/.vim/after/ftplugin/todofile.lua b/.vim/after/ftplugin/todofile.lua
new file mode 100644
index 0000000..2080d39
--- /dev/null
+++ b/.vim/after/ftplugin/todofile.lua
@@ -0,0 +1,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 })