Skip to content

Commit 1fad3a4

Browse files
committed
Merge branch 'dev'
2 parents fae5ae2 + a5042c6 commit 1fad3a4

File tree

3 files changed

+175
-42
lines changed

3 files changed

+175
-42
lines changed

README.md

+42-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,27 @@ Usage
2727

2828
Plugin is automatically applied for files with `.todo` extension.
2929

30-
##### Key bindings
30+
##### TODO Items
31+
32+
The sequence matching the expression '^ [ ] ' marks a line as a TODO list item.
33+
34+
###### Example
35+
36+
```
37+
[ ] Not done
38+
[X] Done
39+
```
40+
41+
##### Commands
42+
43+
* `:VimTodoListsCreateNewItemAbove` - creates a new item in a line above cursor
44+
* `:VimTodoListsCreateNewItemBelow` - creates a new item in a line below cursor
45+
* `:VimTodoListsCreateNewItem` - creates a new item in current line
46+
* `:VimTodoListsGoToNextItem` - go to the next item
47+
* `:VimTodoListsGoToPreviousItem` - go to the previous item
48+
* `:VimTodoListsToggleItem` - toggles the item
49+
50+
##### Default key mappings
3151

3252
###### Item editing mode
3353

@@ -45,6 +65,23 @@ Plugin is automatically applied for files with `.todo` extension.
4565
* `<Space>` - toggle current item
4666
* `<leader>e` - switch to item editing mode
4767

68+
##### Custom key mappings
69+
70+
The `g:VimTodoListsCustomKeyMapper` variable should contain a name of the function
71+
implementing custom mappings.
72+
73+
###### Example
74+
75+
```
76+
let g:VimTodoListsCustomKeyMapper = 'VimTodoListsCustomMappings'
77+
78+
function! VimTodoListsCustomMappings()
79+
nnoremap <buffer> s :VimTodoListsToggleItem<CR>
80+
nnoremap <buffer> <Space> :VimTodoListsToggleItem<CR>
81+
noremap <buffer> <leader>e :silent call VimTodoListsSetItemMode()<CR>
82+
endfunction
83+
```
84+
4885
Future features
4986
---------------
5087

@@ -79,6 +116,10 @@ Changelog
79116

80117
* Fixes broken compatibility with the [filestyle](https://github.com/aserebryakov/filestyle) plugin
81118

119+
#### 0.2.0
120+
121+
* Adds an option to configure custom key mappings
122+
82123
Credits
83124
-------
84125

doc/vim-todo-lists.txt

+66-33
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
*vim-todo-lists.txt* Version 0.1.1
1+
*vim-todo-lists.txt* Version 0.2.0
22
*vim-todo-lists*
33

44
Plugin for TODO lists management.
55

66
==============================================================================
77
CONTENTS *VimTodoListsContents*
88

9-
1. Introduction .... |VimTodoListsIntroduction|
10-
2. Installation .... |VimTodoListsInstallation|
11-
3. Usage ........... |VimTodoListsUsage|
12-
4. Contribution .... |VimTodoListsContribution|
13-
5. Future Features.. |VimTodoListsFutureFeatures|
14-
6. License ......... |VimTodoListsLicense|
15-
7. Changelog ....... |VimTodoListsChangelog|
16-
8. Credits ......... |VimTodoListsCredits|
9+
1. Introduction .... |VimTodoListsIntroduction|
10+
2. Installation .... |VimTodoListsInstallation|
11+
3. Usage ........... |VimTodoListsUsage|
12+
4. Contribution .... |VimTodoListsContribution|
13+
5. Future Features.. |VimTodoListsFutureFeatures|
14+
6. License ......... |VimTodoListsLicense|
15+
7. Changelog ....... |VimTodoListsChangelog|
16+
8. Credits ......... |VimTodoListsCredits|
1717

1818
==============================================================================
1919
1. Introduction *VimTodoListsIntroduction*
@@ -29,41 +29,70 @@ See |VimTodoListsFutureFeatures|.
2929
2. Installation *VimTodoListsInstallation*
3030

3131
Pathogen:
32-
>
33-
$ cd ~/.vim/bundle
34-
$ git clone https://github.com/aserebryakov/vim-todo-lists.git
35-
<
32+
33+
$ cd ~/.vim/bundle
34+
$ git clone https://github.com/aserebryakov/vim-todo-lists.git
35+
3636
NeoBundle:
37-
>
38-
NeoBundle 'aserebryakov/vim-todo-lists'
39-
<
37+
38+
NeoBundle 'aserebryakov/vim-todo-lists'
39+
4040
Without plugin manager:
4141

42-
Clone or download this repository and copy its contents to your ~/.vim/
43-
directory.
42+
Clone or download this repository and copy its contents to your ~/.vim/
43+
directory.
4444

4545
==============================================================================
4646
3. Usage *VimTodoListsUsage*
4747

4848
Plugin is automatically applied for files with `.todo` extension.
4949

50-
Key bindings in item editing mode
51-
---------------------------------
50+
TODO Items
51+
----------
52+
53+
The sequence matching the expression '^ [ ] ' marks a line as a TODO list
54+
item.
55+
56+
Example
57+
-------
58+
59+
[ ] Not done
60+
[X] Done
5261

53-
* j - go to next item
54-
* k - go to previous item
55-
* o - create new item above the cursor
56-
* O - create new item below the cursor
57-
* <Space> - toggle current item
58-
* <CR> - create new item in insert mode
59-
* <leader>e - switch to normal editing mode
62+
Commands
63+
--------
64+
*:VimTodoListsCreateNewItemAbove* *:VimTodoListsCreateNewItemBelow*
65+
*:VimTodoListsCreateNewItem* *:VimTodoListsGoToNextItem*
66+
*:VimTodoListsGoToPreviousItem* *:VimTodoListsToggleItem*
6067

61-
Key bindings in normal editing mode
62-
---------------------------------
68+
* :VimTodoListsCreateNewItemAbove - creates a new item in a line above cursor
69+
* :VimTodoListsCreateNewItemBelow - creates a new item in a line below cursor
70+
* :VimTodoListsCreateNewItem - creates a new item in current line
71+
* :VimTodoListsGoToNextItem - go to the next item
72+
* :VimTodoListsGoToPreviousItem - go to the previous item
73+
* :VimTodoListsToggleItem - toggles the item
6374

64-
* j, k, o, O, <CR> - no special behavior
65-
* <Space> - toggle current item
66-
* <leader>e - switch to item editing mode
75+
76+
Default key bindings
77+
--------------------
78+
79+
Item editing mode
80+
-----------------
81+
82+
* j - go to next item
83+
* k - go to previous item
84+
* o - create new item above the cursor
85+
* O - create new item below the cursor
86+
* <Space> - toggle current item
87+
* <CR> - create new item in insert mode
88+
* <leader>e - switch to normal editing mode
89+
90+
Normal editing mode
91+
-------------------
92+
93+
* j, k, o, O, <CR> - no special behavior
94+
* <Space> - toggle current item
95+
* <leader>e - switch to item editing mode
6796

6897
==============================================================================
6998
4. Future Features *VimTodoListsFutureFeatures*
@@ -79,7 +108,7 @@ Key bindings in normal editing mode
79108

80109
Source code and issues are hosted on GitHub:
81110

82-
https://github.com/aserebryakov/vim-todo-lists
111+
https://github.com/aserebryakov/vim-todo-lists
83112

84113
==============================================================================
85114
6. License *VimTodoListsLicense*
@@ -119,6 +148,10 @@ SOFTWARE.
119148

120149
* Fixes broken compatibility with the [filestyle] plugin
121150

151+
0.2.0
152+
153+
* Adds an option to configure custom key mappings
154+
122155
==============================================================================
123156
8. Credits *VimTodoListsCredits*
124157

plugin/vim-todo-lists.vim

+67-8
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,19 @@ function! VimTodoListsInit()
2828
setlocal shiftwidth=2 expandtab
2929
setlocal cursorline
3030
setlocal noautoindent
31-
call VimTodoListsSetItemMode()
31+
32+
if exists('g:VimTodoListsCustomKeyMapper')
33+
try
34+
call call(g:VimTodoListsCustomKeyMapper, [])
35+
catch
36+
echo 'VimTodoLists: Error in custom key mapper.'
37+
\.' Falling back to default mappings'
38+
call VimTodoListsSetItemMode()
39+
endtry
40+
else
41+
call VimTodoListsSetItemMode()
42+
endif
43+
3244
endfunction
3345

3446

@@ -38,20 +50,61 @@ function! VimTodoListsSetNormalMode()
3850
nunmap <buffer> O
3951
nunmap <buffer> j
4052
nunmap <buffer> k
41-
nnoremap <buffer> <Space> :silent call VimTodoListsToggleItem()<CR>
53+
nnoremap <buffer> <Space> :VimTodoListsToggleItem<CR>
4254
noremap <buffer> <leader>e :silent call VimTodoListsSetItemMode()<CR>
4355
endfunction
4456

4557

4658
" Sets mappings for faster item navigation and editing
4759
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>
60+
nnoremap <buffer> o :VimTodoListsCreateNewItemBelow<CR>
61+
nnoremap <buffer> O :VimTodoListsCreateNewItemAbove<CR>
62+
nnoremap <buffer> j :VimTodoListsGoToNextItem<CR>
63+
nnoremap <buffer> k :VimTodoListsGoToPreviousItem<CR>
64+
nnoremap <buffer> <Space> :VimTodoListsToggleItem<CR>
5365
noremap <buffer> <leader>e :silent call VimTodoListsSetNormalMode()<CR>
54-
inoremap <buffer> <CR> <CR> [ ]
66+
inoremap <buffer> <CR> <CR><ESC>:VimTodoListsCreateNewItem<CR>
67+
endfunction
68+
69+
70+
" Creates a new item above the current line
71+
function! VimTodoListsCreateNewItemAbove()
72+
normal! O [ ]
73+
startinsert!
74+
endfunction
75+
76+
77+
" Creates e new item below the current line
78+
function! VimTodoListsCreateNewItemBelow()
79+
normal! o [ ]
80+
startinsert!
81+
endfunction
82+
83+
84+
" Creates e new item in the current line
85+
function! VimTodoListsCreateNewItem()
86+
normal! 0i [ ]
87+
startinsert!
88+
endfunction
89+
90+
91+
" Moves te cursor to the next item
92+
function! VimTodoListsGoToNextItem()
93+
normal! $
94+
silent exec '/^ \[.\]'
95+
silent exec 'noh'
96+
normal! f[
97+
normal! l
98+
endfunction
99+
100+
101+
" Moves te cursor to the previous item
102+
function! VimTodoListsGoToPreviousItem()
103+
normal! 0
104+
silent exec '?^ \[.\]'
105+
silent exec 'noh'
106+
normal! f[
107+
normal! l
55108
endfunction
56109

57110

@@ -84,5 +137,11 @@ if !exists('g:vimtodolists_plugin')
84137
augroup end
85138

86139
"Defining plugin commands
140+
command! VimTodoListsCreateNewItemAbove silent call VimTodoListsCreateNewItemAbove()
141+
command! VimTodoListsCreateNewItemBelow silent call VimTodoListsCreateNewItemBelow()
142+
command! VimTodoListsCreateNewItem silent call VimTodoListsCreateNewItem()
143+
command! VimTodoListsGoToNextItem silent call VimTodoListsGoToNextItem()
144+
command! VimTodoListsGoToPreviousItem silent call VimTodoListsGoToPreviousItem()
145+
command! VimTodoListsToggleItem silent call VimTodoListsToggleItem()
87146
endif
88147

0 commit comments

Comments
 (0)