Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template Addition #19

Open
kapilnchauhan77 opened this issue Jul 31, 2020 · 3 comments
Open

Template Addition #19

kapilnchauhan77 opened this issue Jul 31, 2020 · 3 comments

Comments

@kapilnchauhan77
Copy link

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>>
@kapilnchauhan77
Copy link
Author

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

For Time Updation with save

@vuciv
Copy link
Owner

vuciv commented Jul 31, 2020

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

Thank you for your contribution :)

@kapilnchauhan77
Copy link
Author

@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>>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants