Skip to content

Commit 5b3a9ec

Browse files
committed
Implements basic functionality for TODO files
Keys are remapped for: * Fast navigation between items * Easy adding new items * Fast toggling items
1 parent 1de0078 commit 5b3a9ec

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

plugin/vim-todo-lists.vim

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
" MIT License
2+
"
3+
" Copyright (c) 2017 Alexander Serebryakov
4+
"
5+
" Permission is hereby granted, free of charge, to any person obtaining a copy
6+
" of this software and associated documentation files (the "Software"), to
7+
" deal in the Software without restriction, including without limitation the
8+
" rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9+
" sell copies of the Software, and to permit persons to whom the Software is
10+
" furnished to do so, subject to the following conditions:
11+
"
12+
" The above copyright notice and this permission notice shall be included in
13+
" all copies or substantial portions of the Software.
14+
"
15+
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
" AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
" LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20+
" FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21+
" IN THE SOFTWARE.
22+
23+
24+
" Initializes plugin settings and mappings
25+
function! VimTodoListsInit()
26+
set filetype=todo
27+
setlocal tabstop=2
28+
setlocal shiftwidth=2 expandtab
29+
setlocal cursorline
30+
setlocal noautoindent
31+
nnoremap <buffer> o o [ ]
32+
nnoremap <buffer> O O [ ]
33+
nnoremap <buffer> j $/^ \[.\]<CR>:noh<CR> f f
34+
nnoremap <buffer> k 0?^ \[.\]<CR>:noh<CR> f f
35+
nnoremap <buffer> <Space> :call VimTodoListsToggleItem()<CR>
36+
inoremap <buffer> <CR> <CR> [ ]
37+
endfunction
38+
39+
40+
" Toggles todo item in list
41+
function! VimTodoListsToggleItem()
42+
let l:line = getline('.')
43+
44+
if match(l:line, '^ \[ \] .*') != -1
45+
call setline('.', substitute(l:line, '^ \[ \] ', ' [X] ', ''))
46+
elseif match(l:line, '^ \[X\] .*') != -1
47+
call setline('.', substitute(l:line, '^ \[X\] ', ' [ ] ', ''))
48+
endif
49+
50+
endfunction
51+
52+
53+
"Plugin startup code
54+
if !exists('g:vimtodolists_plugin')
55+
let g:vimtodolists_plugin = 1
56+
57+
"Defining auto commands
58+
augroup filestyle_auto_commands
59+
autocmd!
60+
autocmd BufRead,BufNewFile *.todo call VimTodoListsInit()
61+
augroup end
62+
63+
"Defining plugin commands
64+
endif
65+

0 commit comments

Comments
 (0)