Implemented sorting on visual selection.

This commit is contained in:
Leandro Freitas
2015-04-16 20:25:58 -03:00
parent b8a5bd64ca
commit 639fcd85a2
5 changed files with 29 additions and 9 deletions

View File

@@ -81,18 +81,38 @@ function! TodoTxtRemoveCompleted()
:g/^x /call add(l:completed, getline(line(".")))|d
call s:AppendToFile(l:done_file, l:completed)
endfunction
function! TodoTxtSortByContext() range
execute a:firstline . "," . a:lastline . "sort /\\(^\\| \\)\\zs@[^[:blank:]]\\+/ r"
endfunction
function! TodoTxtSortByProject() range
execute a:firstline . "," . a:lastline . "sort /\\(^\\| \\)\\zs+[^[:blank:]]\\+/ r"
endfunction
" Mappings {{{1
" Sort tasks {{{2
if !hasmapto("<leader>s",'n')
if !hasmapto("<leader>s",'n')
nnoremap <script> <silent> <buffer> <leader>s :%sort<CR>
endif
if !hasmapto("<leader>s",'v')
vnoremap <script> <silent> <buffer> <leader>s :sort<CR>
endif
if !hasmapto("<leader>s@",'n')
if !hasmapto("<leader>s@",'n')
nnoremap <script> <silent> <buffer> <leader>s@ :%call TodoTxtSortByContext()<CR>
endif
if !hasmapto("<leader>s@",'v')
vnoremap <script> <silent> <buffer> <leader>s@ :call TodoTxtSortByContext()<CR>
endif
if !hasmapto("<leader>s+",'n')
if !hasmapto("<leader>s+",'n')
nnoremap <script> <silent> <buffer> <leader>s+ :%call TodoTxtSortByProject()<CR>
endif
if !hasmapto("<leader>s+",'v')
vnoremap <script> <silent> <buffer> <leader>s+ :call TodoTxtSortByProject()<CR>
endif