@@ -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
@@ -108,16 +110,17 @@ function! VimTodoListsGoToPreviousItem()
108110endfunction
109111
110112
111- " Toggles todo item in list
112- function ! VimTodoListsToggleItem ()
113- let l: line = getline (' .' )
114-
115- if match (l: line , ' ^\s*\[ \].*' ) != -1
116- call setline (' .' , substitute (l: line , ' ^\(\s*\)\[ \]' , ' \1[X]' , ' ' ))
117- elseif match (l: line , ' ^\s*\[X\] .*' ) != -1
118- call setline (' .' , substitute (l: line , ' ^\(\s*\)\[X\]' , ' \1[ ]' , ' ' ))
119- endif
113+ " Toggles todo items in specified range
114+ function ! VimTodoListsToggleItemsRange ()
115+ for lineno in range (a: firstline , a: lastline )
116+ let l: line = getline (lineno)
120117
118+ if match (l: line , ' ^\s*\[ \].*' ) != -1
119+ call setline (lineno, substitute (l: line , ' ^\(\s*\)\[ \]' , ' \1[X]' , ' ' ))
120+ elseif match (l: line , ' ^\s*\[X\] .*' ) != -1
121+ call setline (lineno, substitute (l: line , ' ^\(\s*\)\[X\]' , ' \1[ ]' , ' ' ))
122+ endif
123+ endfor
121124endfunction
122125
123126
@@ -142,6 +145,6 @@ if !exists('g:vimtodolists_plugin')
142145 command ! VimTodoListsCreateNewItem silent call VimTodoListsCreateNewItem ()
143146 command ! VimTodoListsGoToNextItem silent call VimTodoListsGoToNextItem ()
144147 command ! VimTodoListsGoToPreviousItem silent call VimTodoListsGoToPreviousItem ()
145- command ! VimTodoListsToggleItem silent call VimTodoListsToggleItem ()
148+ command ! - range VimTodoListsToggleItem silent <line1> , <line2> call VimTodoListsToggleItemsRange ()
146149endif
147150
0 commit comments