Skip to main content

How to create a template snippet in VS Code that you can use after

· 4 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

Typing that boilerplate from scratch every time is not only tedious, but also error-prone. Fortunately, if you're using Visual Studio Code, there are excellent ways to automate this process by creating custom templates or snippets. Let's walk through some effective strategies for doing just that.


The Problem​

Here’s what you might be typing manually at the start of every new article:

---
title: "My New Article"
description: "An insightful dive into..."
slug: "my-new-article"
date: "2025-07-18"
authors: ["Your Name"]
tags: ["python", "vscode", "markdown"]
---

Doing this for each new post becomes annoying very quickly


You want to reduce friction so that every time you begin writing a new article, you already have this pre-filled. Ideally, you should just hit a shortcut or trigger a command and the template is inserted for you.

Solution 1: VSCode User Snippets​

Visual Studio Code allows you to create user-defined snippets for any language. Markdown (markdown) is supported out of the box.

đź”§ How to Create a Markdown Snippet Press Ctrl+Shift+P (or Cmd+Shift+P on macOS) Search for Preferences: Configure User Snippets Choose markdown.json or create a new global snippet file. Add your template like so:

{
"Blog Front Matter": {
"prefix": "blogmeta",
"body": [
"---",
"title: \"$1\"",
"description: \"$2\"",
"slug: \"${3:slug-goes-here}\"",
"date: \"${4:${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}}\"",
"authors: [\"Your Name\"]",
"tags: [\"$5\"]",
"---",
"",
"$0"
],
"description": "Insert front matter for blog post"
}

Now, when you type blogmeta in a Markdown file and press Tab, the template appears. You can tab between fields to fill them out quickly. The variables like ${CURRENT_YEAR} are dynamically inserted.

Solution 2: File Templates with Extensions​

Another excellent route is using file templates. You can create a base .md file and reuse it.

Use an Extension: "File Templates" or "Templates for VSCode" Install the Templates extension by gruntfuggly. Open command palette → Templates: Save File as Template Create a new Markdown file with your boilerplate and save it as a template. Next time, open the palette → Templates: Insert Template to drop it into any file. 💡 Bonus: Git Hooks for Validation

If you’re using git and want to enforce the presence of front matter in each .md file before committing, consider using a pre-commit hook.

Create a .git/hooks/pre-commit file:

 !/bin/bash

if grep -L '^---' *.md | grep -q .; then
echo "Some markdown files are missing front matter!"
exit 1
fi

This prevents you from committing files without metadata.

Summary​

Writing blog posts in Markdown doesn’t have to be repetitive. Here are your best tools to streamline the workflow:

VSCode Snippets: Perfect for inserting templates on demand inside Markdown files. File Templates Extensions: Great for starting new articles based on predefined files. Git Hooks: Optional step to enforce discipline and prevent omissions. Combine these tools and you’ll save time, reduce errors, and focus more on what matters-your content.