From 3fdf1894711f6b49b5e397e833ca09585e4a73cf Mon Sep 17 00:00:00 2001 From: jdhao Date: Sat, 21 Dec 2019 20:48:02 +0800 Subject: [PATCH] Update meta markdown snippets The original snippet use vim interpolation and the date keeps changing while we are inside the snippet region, which is not desired. According to https://www.youtube.com/watch?v=JJQYwt6Diro, we can use Python interpolation and check if snip.c is empty to see if the interpolation has been finished. If the interpolation has finished (snip.c is empty in this condition), the date will be fixed and does not change when we are inside the snippet region. --- my_snippets/markdown.snippets | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/my_snippets/markdown.snippets b/my_snippets/markdown.snippets index 3b14ea4..d9ef5b8 100644 --- a/my_snippets/markdown.snippets +++ b/my_snippets/markdown.snippets @@ -18,7 +18,9 @@ endsnippet snippet "meta(data)?" "Markdown metadata front matter" br --- title: "$1" -date: `!v strftime("%Y-%m-%d %H:%M:%S%z")` +date: `!p from datetime import datetime +if not snip.c: + snip.rv=datetime.now().strftime("%Y-%m-%d %H:%M:%S%z")` tags: [$2] categories: [$3] ---