Moving completed tasks
Presuming that a done line looks like this:
- ~A completed task~
Then you can do so with a :global
command that performs a :move
:
:g/^- \~.*\~$/m/^# Things done/+1
:g # find lines that match
/^- \~.*\~$/ # the regular expression /^- \~.*\~$/
m # and move them below
+1 # one line below
/^# Things done/ # the line that matches /# Things done/
The regular expression:
/^- \~.*\~$/
^ # the start of the line
- # a markdown list item
\~ # a tilde
.* # anything
\~ # another tilde
$ # the end of the line
You're probably not going to want to type this out every time, so why not make it into a mapping:
:nnoremap <leader>c :g/^- \~.*\~$/m/^# Things done/+1<CR>
Now you can move completed items just by pressing \c.
Appending the time
You can use a similar command to append the current date:
:g/^- \~.*\~$/call setline('.', getline('.') . ' ' . strftime('%x'))
This works very similarly, but instead of moving the lines, it appends the current date to them. (See :help strftime
, :help getline
, and :help setline
.)
Doing both at once
If you don't want two separate mappings, you can wrap them in a function:
function CompleteTasks() abort
g/^- \~.*\~$/m/^# Things done/+1
g/^- \~.*\~$/call setline('.', getline('.') . ' ' . strftime('%c'))
endfunction
nnoremap <leader>c :call CompleteTasks()<CR>