mirror of
https://github.com/jdhao/nvim-config.git
synced 2025-06-08 14:14:33 +02:00
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.
49 lines
920 B
Plaintext
49 lines
920 B
Plaintext
global !p
|
|
def gen_header(snip):
|
|
placeholders_string = snip.buffer[snip.line].strip()
|
|
level = int(placeholders_string[0])
|
|
|
|
# erase current line
|
|
snip.buffer[snip.line] = ""
|
|
line_content = "#"*level + " ${1:Section Name} " + "#"*level
|
|
line_content += '\n\n$0'
|
|
|
|
snip.expand_anon(line_content)
|
|
endglobal
|
|
|
|
snippet kbd "HTML kbd tag"
|
|
<kbd>${1:KEY}</kbd>$0
|
|
endsnippet
|
|
|
|
snippet "meta(data)?" "Markdown metadata front matter" br
|
|
---
|
|
title: "$1"
|
|
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]
|
|
---
|
|
$0
|
|
endsnippet
|
|
|
|
snippet more "HTML more tag"
|
|
<!--more-->
|
|
endsnippet
|
|
|
|
snippet img "Aligned image using HTML tag"
|
|
<p align="center">
|
|
<img src="${1:URL}">
|
|
</p>
|
|
$0
|
|
endsnippet
|
|
|
|
snippet link "Markdown links"
|
|
[$1]($2)$0
|
|
endsnippet
|
|
|
|
post_jump "gen_header(snip)"
|
|
snippet "h([1-6])" "Markdown header" br
|
|
`!p snip.rv = match.group(1)`
|
|
endsnippet
|