here we go
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*.swp
|
||||
doc/tags
|
||||
41
README.markdown
Normal file
41
README.markdown
Normal file
@@ -0,0 +1,41 @@
|
||||
### Quick install
|
||||
|
||||
git clone git://github.com/freitass/todo.txt-vim.git
|
||||
cd todo.txt-vim
|
||||
cp -R * ~/.vim
|
||||
|
||||
|
||||
This plugin gives syntax highlighting to [todo.txt](http://todotxt.com/) files. It also defines a few mappings, to help with editing these files:
|
||||
|
||||
`<leader>-s` : Sort the file
|
||||
|
||||
`<leader>-s+` : Sort the file on +Projects
|
||||
|
||||
`<leader>-s@` : Sort the file on @Contexts
|
||||
|
||||
`<leader>-sd` : Sort @_sched entries by due-date
|
||||
|
||||
`<leader>-j` : Lower the priority of the current line
|
||||
|
||||
`<leader>-k` : Increase the priority of the current line
|
||||
|
||||
`<leader>-a` : Add the priority (A) to the current line
|
||||
|
||||
`<leader>-b` : Add the priority (B) to the current line
|
||||
|
||||
`<leader>-c` : Add the priority (C) to the current line
|
||||
|
||||
`<leader>-d` : Insert the current date
|
||||
|
||||
`date<tab>` : (Insert mode) Insert the current date
|
||||
|
||||
Removed bindings:
|
||||
|
||||
`<leader>-x` : Mark task as done (inserts current date as completion date)
|
||||
|
||||
`<leader>-X` : Mark all tasks as completed
|
||||
|
||||
`<leader>-D` : Move completed tasks to done.txt
|
||||
|
||||
If you want the help installed, run ":helptags ~/.vim/doc" inside vim after having copied the files.
|
||||
Then you will be able to get the commands help with: :h todo.txt
|
||||
32
doc/todo.txt
Normal file
32
doc/todo.txt
Normal file
@@ -0,0 +1,32 @@
|
||||
*todo.txt*
|
||||
|
||||
==============================================================================
|
||||
COMMANDS *todo-commands*
|
||||
|
||||
`<leader>-s` : Sort the file
|
||||
|
||||
`<leader>-s+` : Sort the file on +Projects
|
||||
|
||||
`<leader>-s@` : Sort the file on @Contexts
|
||||
|
||||
`<leader>-j` : Lower the priority of the current line
|
||||
|
||||
`<leader>-k` : Increase the priority of the current line
|
||||
|
||||
`<leader>-a` : Add the priority (A) to the current line
|
||||
|
||||
`<leader>-b` : Add the priority (B) to the current line
|
||||
|
||||
`<leader>-c` : Add the priority (C) to the current line
|
||||
|
||||
`<leader>-d` : Insert the current date
|
||||
|
||||
`date<tab>` : (Insert mode) Insert the current date
|
||||
|
||||
`<leader>-x` : Mark task as done (inserts current date as completion date)
|
||||
|
||||
`<leader>-X` : Mark all tasks as completed
|
||||
|
||||
`<leader>-D` : Move completed tasks to done.txt
|
||||
|
||||
<leader> is \ by default, so <leader>-s means you type \s
|
||||
13
done.txt
Normal file
13
done.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
x 2011-05-30 Create README.markdown to be published in github @doc
|
||||
x 2011-05-30 Implement colorized priorities @syntax
|
||||
x 2011-05-30 Implement filetype detection @ftdetect
|
||||
x 2011-05-30 Sort lines per priority @ftplugin
|
||||
x 2011-05-31 Highlight date, project and context of tasks with no priority @syntax
|
||||
x 2011-05-31 Stop breaking lines automatically @ftplugin
|
||||
x 2011-06-06 Easier date input @ftplugin
|
||||
x 2011-06-06 Implement foldings @ftplugin
|
||||
x 2014-04-27 2011-05-30 Contact main project for reference
|
||||
x 2014-11-01 2011-05-30 Map commands to add, rm, ls, pri, depri etc @ftplugin
|
||||
x 2014-11-01 2011-05-31 Start documentation @doc
|
||||
x 2014-11-01 2011-06-01 Improve syntax file @syntax
|
||||
x 2014-11-01 2011-06-06 Check file syntax @syntax
|
||||
10
ftdetect/todo.vim
Normal file
10
ftdetect/todo.vim
Normal file
@@ -0,0 +1,10 @@
|
||||
" File: todo.txt.vim
|
||||
" Description: Todo.txt filetype detection
|
||||
" Author: Leandro Freitas <freitass@gmail.com>
|
||||
" License: Vim license
|
||||
" Website: http://github.com/freitass/todo.txt-vim
|
||||
" Version: 0.1
|
||||
|
||||
autocmd BufNewFile,BufRead [Tt]odo.txt set filetype=todo
|
||||
autocmd BufNewFile,BufRead [Dd]one.txt set filetype=todo
|
||||
|
||||
222
ftplugin/todo.vim
Normal file
222
ftplugin/todo.vim
Normal file
@@ -0,0 +1,222 @@
|
||||
" File: todo.txt.vim
|
||||
" Description: Todo.txt filetype detection
|
||||
" Author: Leandro Freitas <freitass@gmail.com>
|
||||
" License: Vim license
|
||||
" Website: http://github.com/freitass/todo.txt-vim
|
||||
" Version: 0.4
|
||||
|
||||
" Save context {{{1
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
" General options {{{1
|
||||
" Some options lose their values when window changes. They will be set every
|
||||
" time this script is invocated, which is whenever a file of this type is
|
||||
" created or edited.
|
||||
setlocal textwidth=0
|
||||
setlocal wrapmargin=0
|
||||
|
||||
" Functions {{{1
|
||||
function! s:TodoTxtRemovePriority()
|
||||
:s/^(\w)\s\+//ge
|
||||
endfunction
|
||||
|
||||
function! TodoTxtPrependDate()
|
||||
normal! 0"=strftime("%Y-%m-%d ")
|
||||
P
|
||||
endfunction
|
||||
|
||||
function! TodoTxtMarkAsDone()
|
||||
call s:TodoTxtRemovePriority()
|
||||
call TodoTxtPrependDate()
|
||||
normal! Ix
|
||||
endfunction
|
||||
|
||||
function! TodoTxtMarkAllAsDone()
|
||||
:g!/^x /:call TodoTxtMarkAsDone()
|
||||
endfunction
|
||||
|
||||
function! s:AppendToFile(file, lines)
|
||||
let l:lines = []
|
||||
|
||||
" Place existing tasks in done.txt at the beggining of the list.
|
||||
if filereadable(a:file)
|
||||
call extend(l:lines, readfile(a:file))
|
||||
endif
|
||||
|
||||
" Append new completed tasks to the list.
|
||||
call extend(l:lines, a:lines)
|
||||
|
||||
" Write to file.
|
||||
call writefile(l:lines, a:file)
|
||||
endfunction
|
||||
|
||||
function! TodoTxtRemoveCompleted()
|
||||
" Check if we can write to done.txt before proceeding.
|
||||
let l:target_dir = expand('%:p:h')
|
||||
let l:done_file = l:target_dir.'/done.txt'
|
||||
if !filewritable(l:done_file) && !filewritable(l:target_dir)
|
||||
echoerr "Can't write to file 'done.txt'"
|
||||
return
|
||||
endif
|
||||
|
||||
let l:completed = []
|
||||
:g/^x /call add(l:completed, getline(line(".")))|d
|
||||
call s:AppendToFile(l:done_file, l:completed)
|
||||
endfunction
|
||||
|
||||
function! TodoTxtToggleComplete()
|
||||
if getline('.') =~ '^x'
|
||||
s/\v^x [0-9-]+ +//
|
||||
else
|
||||
exec "s/^/x " . strftime('%Y-%m-%d') . " /"
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Mappings {{{1
|
||||
" Sort tasks {{{2
|
||||
if !hasmapto("<leader>s",'n')
|
||||
nnoremap <script> <silent> <buffer> <leader>s :sort<CR>
|
||||
endif
|
||||
|
||||
if !hasmapto("<leader>s@",'n')
|
||||
nnoremap <script> <silent> <buffer> <leader>s@ :sort /.\{-}\ze@/ <CR>
|
||||
endif
|
||||
|
||||
if !hasmapto("<leader>s+",'n')
|
||||
nnoremap <script> <silent> <buffer> <leader>s+ :sort /.\{-}\ze+/ <CR>
|
||||
endif
|
||||
|
||||
" Increment and Decrement The Priority
|
||||
:set nf=octal,hex,alpha
|
||||
|
||||
function! TodoTxtPrioritizeIncrease()
|
||||
normal! 0f)h
|
||||
endfunction
|
||||
|
||||
function! TodoTxtPrioritizeDecrease()
|
||||
normal! 0f)h
|
||||
endfunction
|
||||
|
||||
function! TodoTxtPrioritizeAdd (priority)
|
||||
" Need to figure out how to only do this if the first visible letter in a line is not (
|
||||
:call TodoTxtPrioritizeAddAction(a:priority)
|
||||
endfunction
|
||||
|
||||
function! TodoTxtPrioritizeAddAction (priority)
|
||||
execute "normal! mq0i(".a:priority.") \<esc>`q"
|
||||
endfunction
|
||||
|
||||
if !hasmapto("<leader>j",'n')
|
||||
nnoremap <script> <silent> <buffer> <leader>j :call TodoTxtPrioritizeIncrease()<CR>
|
||||
endif
|
||||
|
||||
if !hasmapto("<leader>j",'v')
|
||||
vnoremap <script> <silent> <buffer> <leader>j :call TodoTxtPrioritizeIncrease()<CR>
|
||||
endif
|
||||
|
||||
if !hasmapto("<leader>k",'n')
|
||||
nnoremap <script> <silent> <buffer> <leader>k :call TodoTxtPrioritizeDecrease()<CR>
|
||||
endif
|
||||
|
||||
if !hasmapto("<leader>k",'v')
|
||||
vnoremap <script> <silent> <buffer> <leader>k :call TodoTxtPrioritizeDecrease()<CR>
|
||||
endif
|
||||
|
||||
if !hasmapto("<leader>a",'n')
|
||||
nnoremap <script> <silent> <buffer> <leader>a :call TodoTxtPrioritizeAdd('A')<CR>
|
||||
endif
|
||||
|
||||
if !hasmapto("<leader>a",'v')
|
||||
vnoremap <script> <silent> <buffer> <leader>a :call TodoTxtPrioritizeAdd('A')<CR>
|
||||
endif
|
||||
|
||||
if !hasmapto("<leader>b",'n')
|
||||
nnoremap <script> <silent> <buffer> <leader>b :call TodoTxtPrioritizeAdd('B')<CR>
|
||||
endif
|
||||
|
||||
if !hasmapto("<leader>b",'v')
|
||||
vnoremap <script> <silent> <buffer> <leader>b :call TodoTxtPrioritizeAdd('B')<CR>
|
||||
endif
|
||||
|
||||
if !hasmapto("<leader>c",'n')
|
||||
nnoremap <script> <silent> <buffer> <leader>c :call TodoTxtPrioritizeAdd('C')<CR>
|
||||
endif
|
||||
|
||||
if !hasmapto("<leader>c",'v')
|
||||
vnoremap <script> <silent> <buffer> <leader>c :call TodoTxtPrioritizeAdd('C')<CR>
|
||||
endif
|
||||
|
||||
" Insert date {{{2
|
||||
if !hasmapto("date<Tab>",'i')
|
||||
inoremap <script> <silent> <buffer> date<Tab> <C-R>=strftime("%Y-%m-%d")<CR>
|
||||
endif
|
||||
|
||||
if !hasmapto("<leader>d",'n')
|
||||
nnoremap <script> <silent> <buffer> <leader>d :call TodoTxtPrependDate()<CR>
|
||||
endif
|
||||
|
||||
if !hasmapto("<leader>d",'v')
|
||||
vnoremap <script> <silent> <buffer> <leader>d :call TodoTxtPrependDate()<CR>
|
||||
endif
|
||||
|
||||
" Mark done {{{2
|
||||
"if !hasmapto("<leader>x",'n')
|
||||
"nnoremap <script> <silent> <buffer> <leader>x :call TodoTxtMarkAsDone()<CR>
|
||||
"endif
|
||||
|
||||
"if !hasmapto("<leader>x",'v')
|
||||
"vnoremap <script> <silent> <buffer> <leader>x :call TodoTxtMarkAsDone()<CR>
|
||||
"endif
|
||||
|
||||
" Mark all done {{{2
|
||||
"if !hasmapto("<leader>X",'n')
|
||||
"nnoremap <script> <silent> <buffer> <leader>X :call TodoTxtMarkAllAsDone()<CR>
|
||||
"endif
|
||||
|
||||
" Remove completed {{{2
|
||||
"if !hasmapto("<leader>D",'n')
|
||||
"nnoremap <script> <silent> <buffer> <leader>D :call TodoTxtRemoveCompleted()<CR>
|
||||
"endif
|
||||
|
||||
" Toggle Complete {{{2
|
||||
if !hasmapto("<leader>=",'n')
|
||||
nnoremap <script> <silent> <buffer> <leader>= :call TodoTxtToggleComplete()<CR>
|
||||
endif
|
||||
|
||||
" Sort @_sched by due: date {{{2
|
||||
if !hasmapto("<leader>sd".'n')
|
||||
nnoremap <script> <silent> <buffer> <leader>sd :sort n /due:/<CR>
|
||||
endif
|
||||
|
||||
" Folding {{{1
|
||||
" Options {{{2
|
||||
setlocal foldmethod=expr
|
||||
setlocal foldexpr=TodoFoldLevel(v:lnum)
|
||||
setlocal foldtext=TodoFoldText()
|
||||
|
||||
" TodoFoldLevel(lnum) {{{2
|
||||
function! TodoFoldLevel(lnum)
|
||||
" The match function returns the index of the matching pattern or -1 if
|
||||
" the pattern doesn't match. In this case, we always try to match a
|
||||
" completed task from the beginning of the line so that the matching
|
||||
" function will always return -1 if the pattern doesn't match or 0 if the
|
||||
" pattern matches. Incrementing by one the value returned by the matching
|
||||
" function we will return 1 for the completed tasks (they will be at the
|
||||
" first folding level) while for the other lines 0 will be returned,
|
||||
" indicating that they do not fold.
|
||||
return match(getline(a:lnum),'\s@_data\s.\+$') + 1
|
||||
endfunction
|
||||
|
||||
" TodoFoldText() {{{2
|
||||
function! TodoFoldText()
|
||||
" The text displayed at the fold is formatted as '+- N Completed tasks'
|
||||
" where N is the number of lines folded.
|
||||
return '+' . v:folddashes . ' '
|
||||
\ . (v:foldend - v:foldstart + 1)
|
||||
\ . ' Data (contacts/bookmarks) '
|
||||
endfunction
|
||||
|
||||
" Restore context {{{1
|
||||
let &cpo = s:save_cpo
|
||||
" Modeline {{{1
|
||||
52
syntax/todo.vim
Normal file
52
syntax/todo.vim
Normal file
@@ -0,0 +1,52 @@
|
||||
" File: todo.txt.vim
|
||||
" Description: Todo.txt syntax settings
|
||||
" Author: Leandro Freitas <freitass@gmail.com>
|
||||
" License: Vim license
|
||||
" Website: http://github.com/freitass/todo.txt-vim
|
||||
" Version: 0.3
|
||||
|
||||
if exists("b:current_syntax")
|
||||
finish
|
||||
endif
|
||||
|
||||
syntax match TodoDone '^[xX]\s.\+$' contains=TodoDate,TodoProject,TodoContext
|
||||
syntax match TodoPriorityA '^([aA])\s.\+$' contains=TodoDate,TodoProject,TodoContext
|
||||
syntax match TodoPriorityB '^([bB])\s.\+$' contains=TodoDate,TodoProject,TodoContext
|
||||
syntax match TodoPriorityC '^([cC])\s.\+$' contains=TodoDate,TodoProject,TodoContext
|
||||
syntax match TodoPriorityD '^([dD])\s.\+$' contains=TodoDate,TodoProject,TodoContext
|
||||
syntax match TodoPriorityE '^([eE])\s.\+$' contains=TodoDate,TodoProject,TodoContext
|
||||
syntax match TodoPriorityF '^([fF])\s.\+$' contains=TodoDate,TodoProject,TodoContext
|
||||
syntax match TodoPriorityG '^([gG])\s.\+$' contains=TodoDate,TodoProject,TodoContext
|
||||
syntax match TodoPriorityH '^([hH])\s.\+$' contains=TodoDate,TodoProject,TodoContext
|
||||
syntax match TodoPriorityI '^([iI])\s.\+$' contains=TodoDate,TodoProject,TodoContext
|
||||
syntax match TodoPriorityJ '^([jJ])\s.\+$' contains=TodoDate,TodoProject,TodoContext
|
||||
syntax match TodoPriorityK '^([kK])\s.\+$' contains=TodoDate,TodoProject,TodoContext
|
||||
syntax match TodoPriorityL '^([lL])\s.\+$' contains=TodoDate,TodoProject,TodoContext
|
||||
syntax match TodoPriorityM '^([mM])\s.\+$' contains=TodoDate,TodoProject,TodoContext
|
||||
syntax match TodoPriorityN '^([nN])\s.\+$' contains=TodoDate,TodoProject,TodoContext
|
||||
syntax match TodoPriorityO '^([oO])\s.\+$' contains=TodoDate,TodoProject,TodoContext
|
||||
syntax match TodoPriorityP '^([pP])\s.\+$' contains=TodoDate,TodoProject,TodoContext
|
||||
syntax match TodoPriorityQ '^([qQ])\s.\+$' contains=TodoDate,TodoProject,TodoContext
|
||||
syntax match TodoPriorityR '^([rR])\s.\+$' contains=TodoDate,TodoProject,TodoContext
|
||||
syntax match TodoPriorityS '^([sS])\s.\+$' contains=TodoDate,TodoProject,TodoContext
|
||||
syntax match TodoPriorityT '^([tT])\s.\+$' contains=TodoDate,TodoProject,TodoContext
|
||||
syntax match TodoPriorityU '^([uU])\s.\+$' contains=TodoDate,TodoProject,TodoContext
|
||||
syntax match TodoPriorityV '^([vV])\s.\+$' contains=TodoDate,TodoProject,TodoContext
|
||||
syntax match TodoPriorityW '^([wW])\s.\+$' contains=TodoDate,TodoProject,TodoContext
|
||||
syntax match TodoPriorityX '^([xX])\s.\+$' contains=TodoDate,TodoProject,TodoContext
|
||||
syntax match TodoPriorityY '^([yY])\s.\+$' contains=TodoDate,TodoProject,TodoContext
|
||||
syntax match TodoPriorityZ '^([zZ])\s.\+$' contains=TodoDate,TodoProject,TodoContext
|
||||
syntax match TodoDate '\d\{2,4\}-\d\{2\}-\d\{2\}' contains=NONE
|
||||
syntax match TodoProject '\(^\|\W\)+[^[:blank:]]\+' contains=NONE
|
||||
syntax match TodoContext '\(^\|\W\)@[^[:blank:]]\+' contains=NONE
|
||||
|
||||
" Other priority colours might be defined by the user
|
||||
highlight default link TodoDone Comment
|
||||
highlight default link TodoPriorityA Constant
|
||||
highlight default link TodoPriorityB Statement
|
||||
highlight default link TodoPriorityC Identifier
|
||||
highlight default link TodoDate PreProc
|
||||
highlight default link TodoProject Special
|
||||
highlight default link TodoContext Special
|
||||
|
||||
let b:current_syntax = "todo"
|
||||
Reference in New Issue
Block a user