Skip to content

Commit cfd243a

Browse files
committed
Adds items toggling in visual mode (#5)
1 parent 4a83147 commit cfd243a

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,11 @@ Changelog
118118

119119
#### 0.2.0
120120

121-
* Adds an option to configure custom key mappings
121+
* Added an option to configure custom key mappings
122122

123123
#### 0.3.0
124124

125+
* Added items toggling in visual mode
125126
* Improves work with indentations of list items
126127

127128
Credits

doc/vim-todo-lists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,11 @@ SOFTWARE.
150150

151151
0.2.0
152152

153-
* Adds an option to configure custom key mappings
153+
* Added an option to configure custom key mappings
154154

155155
0.3.0
156156

157+
* Added items toggling in visual mode
157158
* Improves work with indentations of list items
158159

159160
==============================================================================

plugin/vim-todo-lists.vim

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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>
5556
endfunction
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>
6769
endfunction
6870

6971

@@ -108,16 +110,17 @@ function! VimTodoListsGoToPreviousItem()
108110
endfunction
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
121124
endfunction
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()
146149
endif
147150

0 commit comments

Comments
 (0)