Skip to content

Commit 3d9f77f

Browse files
committed
Adds commands for item management (#3)
Direct keys remapping with key sequences replaced with commands execution as a preparation to custom mappings.
1 parent fae5ae2 commit 3d9f77f

File tree

1 file changed

+53
-6
lines changed

1 file changed

+53
-6
lines changed

plugin/vim-todo-lists.vim

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,54 @@ endfunction
4545

4646
" Sets mappings for faster item navigation and editing
4747
function! VimTodoListsSetItemMode()
48-
nnoremap <buffer> o o [ ]
49-
nnoremap <buffer> O O [ ]
50-
nnoremap <buffer> j $/^ \[.\]<CR>:noh<CR> f f
51-
nnoremap <buffer> k 0?^ \[.\]<CR>:noh<CR> f f
52-
nnoremap <buffer> <Space> :silent call VimTodoListsToggleItem()<CR>
48+
nnoremap <buffer> o :VimTodoListsCreateNewItemBelow<CR>
49+
nnoremap <buffer> O :VimTodoListsCreateNewItemAbove<CR>
50+
nnoremap <buffer> j :VimTodoListsGoToNextItem<CR>
51+
nnoremap <buffer> k :VimTodoListsGoToPreviousItem<CR>
52+
nnoremap <buffer> <Space> :VimTodoListsToggleItem<CR>
5353
noremap <buffer> <leader>e :silent call VimTodoListsSetNormalMode()<CR>
54-
inoremap <buffer> <CR> <CR> [ ]
54+
inoremap <buffer> <CR> <CR><ESC>:VimTodoListsCreateNewItem<CR>
55+
endfunction
56+
57+
58+
" Creates a new item above the current line
59+
function! VimTodoListsCreateNewItemAbove()
60+
normal! O [ ]
61+
startinsert!
62+
endfunction
63+
64+
65+
" Creates e new item below the current line
66+
function! VimTodoListsCreateNewItemBelow()
67+
normal! o [ ]
68+
startinsert!
69+
endfunction
70+
71+
72+
" Creates e new item in the current line
73+
function! VimTodoListsCreateNewItem()
74+
normal! 0i [ ]
75+
startinsert!
76+
endfunction
77+
78+
79+
" Moves te cursor to the next item
80+
function! VimTodoListsGoToNextItem()
81+
normal! $
82+
silent exec '/^ \[.\]'
83+
silent exec 'noh'
84+
normal! f[
85+
normal! l
86+
endfunction
87+
88+
89+
" Moves te cursor to the previous item
90+
function! VimTodoListsGoToPreviousItem()
91+
normal! 0
92+
silent exec '?^ \[.\]'
93+
silent exec 'noh'
94+
normal! f[
95+
normal! l
5596
endfunction
5697

5798

@@ -84,5 +125,11 @@ if !exists('g:vimtodolists_plugin')
84125
augroup end
85126

86127
"Defining plugin commands
128+
command! VimTodoListsToggleItem silent call VimTodoListsToggleItem()
129+
command! VimTodoListsCreateNewItemAbove silent call VimTodoListsCreateNewItemAbove()
130+
command! VimTodoListsCreateNewItemBelow silent call VimTodoListsCreateNewItemBelow()
131+
command! VimTodoListsCreateNewItem silent call VimTodoListsCreateNewItem()
132+
command! VimTodoListsGoToNextItem silent call VimTodoListsGoToNextItem()
133+
command! VimTodoListsGoToPreviousItem silent call VimTodoListsGoToPreviousItem()
87134
endif
88135

0 commit comments

Comments
 (0)