From 8edb3af29cd085a66b8a76010efe97e198eac109 Mon Sep 17 00:00:00 2001 From: Guangxiong Lin Date: Wed, 10 Apr 2024 20:19:18 +0800 Subject: Add shortcuts to create todo items --- .vim/UltiSnips/markdown.snippets | 3 +++ .vim/after/autoload/markdown.vim | 18 ++++++++++++++++++ .vim/after/ftplugin/markdown.vim | 3 +++ 3 files changed, 24 insertions(+) create mode 100644 .vim/UltiSnips/markdown.snippets create mode 100644 .vim/after/autoload/markdown.vim diff --git a/.vim/UltiSnips/markdown.snippets b/.vim/UltiSnips/markdown.snippets new file mode 100644 index 0000000..6088ea8 --- /dev/null +++ b/.vim/UltiSnips/markdown.snippets @@ -0,0 +1,3 @@ +snippet todo "Create a TODO item" +* TODO :: ${0} +endsnippet diff --git a/.vim/after/autoload/markdown.vim b/.vim/after/autoload/markdown.vim new file mode 100644 index 0000000..1baac57 --- /dev/null +++ b/.vim/after/autoload/markdown.vim @@ -0,0 +1,18 @@ +let s:todo_items = ['TODO', 'DONE'] +let s:todo_items_regex = '\* \(TODO\|DONE\) ::' + +function! markdown#todo_items_set(state) abort + execute 's/' . s:todo_items_regex . '/* ' . a:state . ' ::/' +endfunction + +function! markdown#todo_items_set_next() abort + let l:line = getline('.') + + for i in range(len(s:todo_items)) + if l:line =~# ('.*\* ' . s:todo_items[i] . ' :: .*') + let l:next_todo_item_index = (i + 1) % len(s:todo_items) + let l:next_todo_item = s:todo_items[l:next_todo_item_index] + call markdown#todo_items_set(l:next_todo_item) + endif + endfor +endfunction diff --git a/.vim/after/ftplugin/markdown.vim b/.vim/after/ftplugin/markdown.vim index 9d2b097..a5a6268 100644 --- a/.vim/after/ftplugin/markdown.vim +++ b/.vim/after/ftplugin/markdown.vim @@ -7,3 +7,6 @@ setlocal iskeyword+=[,\- " setlocal formatoptions-=t " setlocal formatoptions-=c + +nnoremap t :call markdown#todo_items_set_next() +nnoremap Td :call markdown#todo_items_set('DONE') -- cgit v1.2.3