zk-org / zk-nvim

Neovim extension for zk
https://github.com/zk-org/zk
GNU General Public License v3.0
503 stars 41 forks source link

How can we input tags from the nvim commandline? #46

Closed kabinspace closed 2 years ago

kabinspace commented 2 years ago

Since we can easily input our title from the nvim commandline like this:

n = { "<cmd>ZkNew { dir = vim.fn.expand('%:p:h'), title = vim.fn.input('Title: ') }<cr>", "New Notes" }

Is there a way we could have same input option for tags as well? This is my .zk/templates/default.md

---
title: {{ title }}
date: {{ date now "long" }}
tags: {{ tags }}
---

{{content}}
mickael-menu commented 2 years ago

The tags template variable doesn't exist when creating new notes. However, you can use a custom extra variable for this:

---
title: {{ title }}
date: {{ date now "long" }}
tags: {{ extra.tags }}
---

{{content}}

Then you can use a similar method to set the extra variable with NeoVim:

n = { "<cmd>ZkNew { dir = vim.fn.expand('%:p:h'), title = vim.fn.input('Title: '), extra = { tags = vim.fn.input('Tags') }}<cr>", "New Notes" }

(Note that extra is a dictionary, I'm not sure the above syntax is correct actually, I didn't test it out myself).

kabinspace commented 2 years ago

Great, the given solution works perfectly fine. Thank you :)