@@ -51,6 +51,7 @@ function! VimTodoListsSetNormalMode()
5151 nunmap <buffer> j
5252 nunmap <buffer> k
5353 nnoremap <buffer> <Space> :VimTodoListsToggleItem<CR>
54+ vnoremap <buffer> <Space> :'<,'> VimTodoListsToggleItem<CR>
5455 noremap <buffer> <leader> e :silent call VimTodoListsSetItemMode()<CR>
5556endfunction
5657
@@ -62,8 +63,9 @@ function! VimTodoListsSetItemMode()
6263 nnoremap <buffer> j :VimTodoListsGoToNextItem<CR>
6364 nnoremap <buffer> k :VimTodoListsGoToPreviousItem<CR>
6465 nnoremap <buffer> <Space> :VimTodoListsToggleItem<CR>
65- noremap <buffer> <leader> e :silent call VimTodoListsSetNormalMode() <CR>
66+ vnoremap <buffer> <Space> :VimTodoListsToggleItem <CR>
6667 inoremap <buffer> <CR> <CR><ESC> :VimTodoListsCreateNewItem<CR>
68+ noremap <buffer> <leader> e :silent call VimTodoListsSetNormalMode()<CR>
6769endfunction
6870
6971
@@ -91,8 +93,8 @@ endfunction
9193" Moves te cursor to the next item
9294function ! VimTodoListsGoToNextItem ()
9395 normal ! $
94- silent exec ' /^ \[.\]'
95- silent exec ' noh'
96+ silent ! exec ' /^\s* \[.\]'
97+ silent ! exec ' noh'
9698 normal ! f [
9799 normal ! l
98100endfunction
@@ -101,21 +103,21 @@ endfunction
101103" Moves te cursor to the previous item
102104function ! VimTodoListsGoToPreviousItem ()
103105 normal ! 0
104- silent exec ' ?^ \[.\]'
105- silent exec ' noh'
106+ silent ! exec ' ?^\s* \[.\]'
107+ silent ! exec ' noh'
106108 normal ! f [
107109 normal ! l
108110endfunction
109111
110112
111- " Toggles todo item in list
113+ " Toggles todo list item
112114function ! VimTodoListsToggleItem ()
113115 let l: line = getline (' .' )
114116
115- if match (l: line , ' ^ \ [ \] .*' ) != -1
116- call setline (' .' , substitute (l: line , ' ^ \ [ \] ' , ' [X] ' , ' ' ))
117- elseif match (l: line , ' ^ \[X\] .*' ) != -1
118- call setline (' .' , substitute (l: line , ' ^ \ [X\] ' , ' [ ] ' , ' ' ))
117+ if match (l: line , ' ^\s*\ [ \].*' ) != -1
118+ call setline (' .' , substitute (l: line , ' ^\(\s*\)\ [ \]' , ' \1 [X]' , ' ' ))
119+ elseif match (l: line , ' ^\s* \[X\] .*' ) != -1
120+ call setline (' .' , substitute (l: line , ' ^\(\s*\)\ [X\]' , ' \1 [ ]' , ' ' ))
119121 endif
120122
121123endfunction
@@ -142,6 +144,6 @@ if !exists('g:vimtodolists_plugin')
142144 command ! VimTodoListsCreateNewItem silent call VimTodoListsCreateNewItem ()
143145 command ! VimTodoListsGoToNextItem silent call VimTodoListsGoToNextItem ()
144146 command ! VimTodoListsGoToPreviousItem silent call VimTodoListsGoToPreviousItem ()
145- command ! VimTodoListsToggleItem silent call VimTodoListsToggleItem ()
147+ command ! - range VimTodoListsToggleItem silent <line1> , <line2> call VimTodoListsToggleItem ()
146148endif
147149
0 commit comments