michal-h21 / vim-zettel

VimWiki addon for managing notes according to Zettelkasten method
MIT License
555 stars 72 forks source link

Add `%random` variable for template files #112

Open drkmrin78 opened 2 years ago

drkmrin78 commented 2 years ago

I think it would be useful to make templates that match the front_matter of other tools, for easier collaboration and integration into other zettelkasten tools. For this, some tools create unique random IDs in the front matter.

similar to #68

Thanks!

michal-h21 commented 2 years ago

Do you mean the similar string as used in %random template for filenames, or just some random number? You can add custom fields to the front_matter, where values can be filled by Vim functions. For example, this configuration can be used to insert a random number in Vim 8.2:

function! s:insert_random()
  let seed = srand()
  return rand(seed)
endfunction

let g:zettel_options = [ {"front_matter" : [["random", function("s:insert_random")]]}]