@@ -51,6 +51,7 @@ function! VimTodoListsSetNormalMode()
51
51
nunmap <buffer> j
52
52
nunmap <buffer> k
53
53
nnoremap <buffer> <Space> :VimTodoListsToggleItem<CR>
54
+ vnoremap <buffer> <Space> :'<,'> VimTodoListsToggleItem<CR>
54
55
noremap <buffer> <leader> e :silent call VimTodoListsSetItemMode()<CR>
55
56
endfunction
56
57
@@ -62,8 +63,9 @@ function! VimTodoListsSetItemMode()
62
63
nnoremap <buffer> j :VimTodoListsGoToNextItem<CR>
63
64
nnoremap <buffer> k :VimTodoListsGoToPreviousItem<CR>
64
65
nnoremap <buffer> <Space> :VimTodoListsToggleItem<CR>
65
- noremap <buffer> <leader> e :silent call VimTodoListsSetNormalMode() <CR>
66
+ vnoremap <buffer> <Space> :VimTodoListsToggleItem <CR>
66
67
inoremap <buffer> <CR> <CR><ESC> :VimTodoListsCreateNewItem<CR>
68
+ noremap <buffer> <leader> e :silent call VimTodoListsSetNormalMode()<CR>
67
69
endfunction
68
70
69
71
@@ -91,8 +93,8 @@ endfunction
91
93
" Moves te cursor to the next item
92
94
function ! VimTodoListsGoToNextItem ()
93
95
normal ! $
94
- silent exec ' /^ \[.\]'
95
- silent exec ' noh'
96
+ silent ! exec ' /^\s* \[.\]'
97
+ silent ! exec ' noh'
96
98
normal ! f [
97
99
normal ! l
98
100
endfunction
@@ -101,21 +103,21 @@ endfunction
101
103
" Moves te cursor to the previous item
102
104
function ! VimTodoListsGoToPreviousItem ()
103
105
normal ! 0
104
- silent exec ' ?^ \[.\]'
105
- silent exec ' noh'
106
+ silent ! exec ' ?^\s* \[.\]'
107
+ silent ! exec ' noh'
106
108
normal ! f [
107
109
normal ! l
108
110
endfunction
109
111
110
112
111
- " Toggles todo item in list
113
+ " Toggles todo list item
112
114
function ! VimTodoListsToggleItem ()
113
115
let l: line = getline (' .' )
114
116
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 [ ]' , ' ' ))
119
121
endif
120
122
121
123
endfunction
@@ -142,6 +144,6 @@ if !exists('g:vimtodolists_plugin')
142
144
command ! VimTodoListsCreateNewItem silent call VimTodoListsCreateNewItem ()
143
145
command ! VimTodoListsGoToNextItem silent call VimTodoListsGoToNextItem ()
144
146
command ! VimTodoListsGoToPreviousItem silent call VimTodoListsGoToPreviousItem ()
145
- command ! VimTodoListsToggleItem silent call VimTodoListsToggleItem ()
147
+ command ! - range VimTodoListsToggleItem silent <line1> , <line2> call VimTodoListsToggleItem ()
146
148
endif
147
149
0 commit comments