Vimwiki: how do I change diary wiki files extention to ".diary.wiki" ?

Created on 4 Apr 2015  路  3Comments  路  Source: vimwiki/vimwiki

I've recently started using vim-template (https://github.com/aperezdc/vim-template) and I'd like to have my diary files opened with a diary template. In order for this to happen automatically, changing the default extension from ".wiki" to ".diary.wiki" would do the trick, but I haven't been able to figure that out.. clues please?

wontfix

Most helpful comment

I can't tell you if the extension can be changed just for the diary (I don't remember such an option), but I can share you my self-hacked solution and a potential way to do it without a workaround (like I use it).

You might be able to load the template based on something like

autocmd BufNewFile */diary/????-??-??.wiki call templateplugin#function('variable')

The following is an over time grown solution that works for me. I didn't find a template framework at that time that fit my needs. Maybe it is interesting for someone. I have to admit that there are probably multiple ways to improve it. Please be aware that I use .md files and not .wiki files, so you might need to adjust this.

autocmd BufNewFile */diary/????-??-??.md call s:new_vimwiki_diary_template()

[...]

function s:new_vimwiki_diary_template()
  " load diary template
  read ~/repos/vimwiki/templates/diary.tpl | execute "normal ggdd"
  " execute VIM_EVAL tag
  %substitute#\[:VIM_EVAL:\]\(.\{-\}\)\[:END_EVAL:\]#\=eval(submatch(1))#ge
  let dow = strftime("%a") " day of week
  let dom = strftime("%e") " day of month
  " ==# is case insensitive
  " bi-weekly
  if (dow ==# "Sat") || (dow ==# "Wed")
     %substitute#%bi-weekly%#
  end
  " weekly
  if (dow ==# "Sat")
     %substitute#%weekly%#
  endif
  " monthly
  if (dow ==# "Sat") && ((dom < 7))
     %substitute#%monthly%#
  endif
  " bi-monthly
  if (dow ==# "Sat") && ((dom < 7) || (dom > 23))
     %substitute#%bi-monthly%#
  endif
  " cut all other lines starting with '%' out
  execute "g/^%/d"
endfunction

The template itself looks as following:

# [:VIM_EVAL:]strftime('%Y-%m-%d')[:END_EVAL:] #

%bi-weekly%* [ ] bi-weekly task entry
%bi-monthly%* [ ] bi-monthly task entry
%monthly%* [ ] monthly task entry
%weekly%* [ ] weekly task entry
%any other commented out line

All 3 comments

I can't tell you if the extension can be changed just for the diary (I don't remember such an option), but I can share you my self-hacked solution and a potential way to do it without a workaround (like I use it).

You might be able to load the template based on something like

autocmd BufNewFile */diary/????-??-??.wiki call templateplugin#function('variable')

The following is an over time grown solution that works for me. I didn't find a template framework at that time that fit my needs. Maybe it is interesting for someone. I have to admit that there are probably multiple ways to improve it. Please be aware that I use .md files and not .wiki files, so you might need to adjust this.

autocmd BufNewFile */diary/????-??-??.md call s:new_vimwiki_diary_template()

[...]

function s:new_vimwiki_diary_template()
  " load diary template
  read ~/repos/vimwiki/templates/diary.tpl | execute "normal ggdd"
  " execute VIM_EVAL tag
  %substitute#\[:VIM_EVAL:\]\(.\{-\}\)\[:END_EVAL:\]#\=eval(submatch(1))#ge
  let dow = strftime("%a") " day of week
  let dom = strftime("%e") " day of month
  " ==# is case insensitive
  " bi-weekly
  if (dow ==# "Sat") || (dow ==# "Wed")
     %substitute#%bi-weekly%#
  end
  " weekly
  if (dow ==# "Sat")
     %substitute#%weekly%#
  endif
  " monthly
  if (dow ==# "Sat") && ((dom < 7))
     %substitute#%monthly%#
  endif
  " bi-monthly
  if (dow ==# "Sat") && ((dom < 7) || (dom > 23))
     %substitute#%bi-monthly%#
  endif
  " cut all other lines starting with '%' out
  execute "g/^%/d"
endfunction

The template itself looks as following:

# [:VIM_EVAL:]strftime('%Y-%m-%d')[:END_EVAL:] #

%bi-weekly%* [ ] bi-weekly task entry
%bi-monthly%* [ ] bi-monthly task entry
%monthly%* [ ] monthly task entry
%weekly%* [ ] weekly task entry
%any other commented out line

@linuxcaffe: no, currently, it's not possible, and I think it's more a responsibility of the template plugin to support more complex file name patterns (maybe it's already possible, I didn't take a look into it) than of Vimwiki to support different extensions. After all, diary files are wiki files and therefore should have the .wiki extension only.

@linuxcaffe, I also wanted to have a different extension for diary files (a .gpg extension to use in conjunction with vim-gnupg). I made a branch that supports this at https://github.com/schmeisers/vimwiki/tree/diary-ext

It creates a per-wiki option for the diary extension:
~
let g:vimwiki_list = [{'path': '~/my_site/',
\ 'index': 'main', 'diary_ext': '.gpg'}]
~

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davy79 picture davy79  路  4Comments

BSDxxxx picture BSDxxxx  路  3Comments

gmarmstrong picture gmarmstrong  路  5Comments

Vitruvia picture Vitruvia  路  5Comments

yangkev picture yangkev  路  5Comments