From 2d689127908c429a29807b3b151abb13d73aab6e Mon Sep 17 00:00:00 2001 From: Jersey <fonseca@uchicago.edu> Date: Sun, 28 Jun 2020 14:19:40 -0500 Subject: Added the ability to uncheck --- ftplugin/markdown_bujo.vim | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/ftplugin/markdown_bujo.vim b/ftplugin/markdown_bujo.vim index 22bdd19..2330b35 100644 --- a/ftplugin/markdown_bujo.vim +++ b/ftplugin/markdown_bujo.vim @@ -1,6 +1,21 @@ +" markdown_bujo.vim - A minimalist todo list manager +" Maintainer: Jersey Fonseca <http://www.jerseyfonseca.com/> +" Version: 0.5 + +" SearchCheck() searches for whether or not BujoCheck... was called on a +" checked or unchecked task. We need to call search() twice with and without +" the 'b' tag because search() only allows you to search forward or backwards, +" not both ways. +" +" search() returns 0 if it the pattern was not found +function <SID>SearchCheck() + return (search('\[\]', 'nc', line('.')) || search('\[\]', 'nbc', line('.'))) +endfunction + " Edit markdown lists " Add and remove bullets with ease +" If we are already checked then we uncheck +nnoremap <expr> <silent> <buffer> <Plug>BujoChecknormal <SID>SearchCheck() ? ':.s/\[\]/\[x\]<Enter>' : ':.s/\[x\]/\[\]<Enter>' nnoremap <silent> <buffer> <Plug>BujoAddnormal i-[] -nnoremap <silent> <buffer> <Plug>BujoChecknormal :.s/\[\]/\[x\]<Enter> inoremap <silent> <buffer> <Plug>BujoAddinsert -[] -inoremap <silent> <buffer> <Plug>BujoCheckinsert <esc>:.s/\[\]/\[x\]<Enter> +inoremap <expr> <silent> <buffer> <Plug>BujoCheckinsert <SID>SearchCheck() ? '<esc>:.s/\[\]/\[x\]<Enter>' : '<esc>:.s/\[x\]/\[\]<Enter>' -- cgit v1.2.3