michal-h21 / vim-zettel

VimWiki addon for managing notes according to Zettelkasten method
MIT License
557 stars 73 forks source link

Order of additonal options in the frontmatter of new notes cannot be changed #62

Open khanmurad opened 4 years ago

khanmurad commented 4 years ago

I would like to insert the preamble some additional options such as default bibtex file etc. My .vimrc setting is the following:

let g:zettel_options = [{"front_matter" : { "tags" : "", "csl": "'/references/apa-tr.csl'", "bibliography": "'/references/zettel.bib'" }, "template" :  "~/.vim/templates/zettel.tpl"}]

It does not matter in what order I put it, the preamble comes out the same:

---
title: Title
date: 2020-08-29 20:25
csl: '/references/apa-tr.csl'
tags: 
bibliography: '/references/zettel.bib'
---

Whereas, I want the tags: at the end:

---
title: Title
date: 2020-08-29 20:25
csl: '/references/apa-tr.csl'
bibliography: '/references/zettel.bib'
tags: 
---

I tried the following with no success:

let g:zettel_options = [{"front_matter" : { "csl": "'/references/apa-tr.csl'", "bibliography": "'/references/zettel.bib'", "tags" : "" }, "template" :  "~/.vim/templates/zettel.tpl"}]

It seems that it sorts additional options by the number of characters in option names (may be not). How can I force it to put tags: at the end of the preamble?

michal-h21 commented 4 years ago

@khanmurad the problem is that front_matter is a dictionary, which doesn't have order in Vim, so you will always get the random sorting. I think I can change the code to accept a list instead of dictionary. It will enable the correct ordering, but the downside is that the specification will be more cumbersome (something like "front_matter" : [ ["csl", "...."], ["bibliography", "..."], ["tags", "....]]`).

michal-h21 commented 4 years ago

It is now possible to use lists, like:

let g:zettel_options = [{"front_matter" : [[ "tags" , ""],[ "csl", "'/references/apa-tr.csl'"],  ["bibliography", "'/references/zettel.bib'"]] }, "template" :  "~/.vim/templates/zettel.tpl"}]

It is not as nice as a dictionary, but it is the only way to support the ordering.