Advertisement
Guest User

Untitled

a guest
Dec 11th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. " Simple todo function
  2. nnoremap <leader>to :ToggleCompletion<cr>ddGpggj
  3.  
  4. function! s:ToggleCompletion()
  5. let save_cursor = getpos(".")
  6. if match(getline('.'), '- \[\s\]') != -1
  7. substitute/\[\s\]/[x]/
  8. else
  9. substitute/\[x\]/[ ]/
  10. endif
  11. call setpos('.', save_cursor)
  12. endfunction
  13.  
  14. command! ToggleCompletion call <sid>ToggleCompletion()
  15. nnoremap X :ToggleCompletion<cr>
  16.  
  17. syntax match doneTodo "\v%(\s+)?- \[x\].*"
  18. highlight link doneTodo Comment
  19.  
  20. function! s:Todo()
  21. let save_cursor = getpos(".")
  22. let has_dash = (match(getline('.'), '\v^\s?- \w') != -1)
  23. if has_dash
  24. s/\v(\s+)?- (.*)/\1- [ ] \2/
  25. call setpos('.', save_cursor)
  26. normal! 4l
  27. else
  28. s/\v(\s+)?(.*)/\1- [ ] \2/
  29. call setpos('.', save_cursor)
  30. normal! 6l
  31. endif
  32. silent! call repeat#set("\<Plug>Todo", 0)
  33. endfunction
  34. command! Todo call <sid>Todo()
  35. nnoremap <Plug>Todo :Todo<cr>
  36. map <leader>nt <Plug>Todo
  37.  
  38. " vim:ft=vim
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement