vuciv / vim-bujo

A minimalist task manager for vim.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Template Addition

kapilnchauhan77 opened this issue · comments

image

Hey, I saw that template addition was not available so I wrote something that will produce the above mentioned result:

function AddTemplate(tmpl_file)
    exe "0read " . a:tmpl_file
    let substDict = {}
    let substDict["date"] = strftime("%Y %b %d %X")
    exe '%s/<<\([^>]*\)>>/\=substDict[submatch(1)]/g'
    set nomodified
    normal G
endfunction
autocmd BufNewFile todo.md call AddTemplate("~/.vim/plugged/vim-bujo/templates/md.skeleton")

The change I think needed is to have it automatically find the template file.

Also my template file (Minor Changes from yours),

  _____ _ __  _ __  _ __
 /_  __/ __ \/ __ \/ __ \
  / / / / / / / / / / / /
 / / / /_/ / /_/ / /_/ /
/_/  \_  _/_  _ /\_  _/

 
 Date:  <<date>>

autocmd BufWritePost todo.md :10s/.*/\=strftime('%Y %b %d %X')/g

For Time Updation with save

@kapilnchauhan77 this is awesome! I will be adding this this weekend.

Thank you for your contribution :)

@vuciv
Here is the updated (bug free) code then:

function AddTemplate(tmpl_file)
    exe "0read " . a:tmpl_file
    let substDict = {}
    let substDict["name"] = split(expand('%:p:h:t'), '\v\n')[0] . " todo"
    let substDict["date"] = strftime("%Y %b %d %X")
    exe '%s/<<\([^>]*\)>>/\=substDict[submatch(1)]/g'
    set nomodified
    normal G
endfunction
autocmd BufNewFile todo.md call AddTemplate("~/.vim/plugged/vim-bujo/templates/md.skeleton")
autocmd BufWritePost todo.md :10s/Date: \zs.*/\=strftime('%Y %b %d %X')/g

Template:

File Name: <<name>>

  _____ _ __  _ __  _ __
 /_  __/ __ \/ __ \/ __ \
  / / / / / / / / / / / /
 / / / /_/ / /_/ / /_/ /
/_/  \_  _/_  _ /\_  _/

 
Date:  <<date>>