From d5392b105406a7060aa9bf7a8b0e053ed517e730 Mon Sep 17 00:00:00 2001 From: jdhao Date: Wed, 18 Dec 2019 21:07:59 +0800 Subject: [PATCH] Add markdown header snippets Now we can type h1, h2, ..., h6 and press to generate header of corresponding level. It is more intuitive than vim-snippets's default snippets for headers, i.e., sec, ssec, and so on. --- my_snippets/markdown.snippets | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/my_snippets/markdown.snippets b/my_snippets/markdown.snippets index 94b408e..a4d0c64 100644 --- a/my_snippets/markdown.snippets +++ b/my_snippets/markdown.snippets @@ -1,3 +1,16 @@ +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$0' + + snip.expand_anon(line_content) +endglobal + snippet kbd "HTML kbd tag" ${1:KEY}$0 endsnippet @@ -26,3 +39,8 @@ 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