···11+---
22+title: How VS Code Snippets can improve your workflow when working with Astro
33+description: Learn how to create and use VS Code snippets to quickly insert frontmatter for Astro content collections. This guide shows how snippets can automate repetitive tasks, speed up Markdown and MDX editing, and improve your Astro workflow.
44+date: 2025-10-28
55+tags:
66+ - Automation
77+ - Education
88+authors:
99+ - trueberryless
1010+cover:
1111+ alt: A collection of old newspaper sheets piled on a wooden table, displaying vintage articles and worn edges.
1212+ image: ../../../../public/blog/starlight-vscode-snippets.jpg
1313+---
1414+1515+This article demonstrates how code snippets can be created in Visual Studio Code that can significantly boost your productivity when regularly working with [Astro's content collections](https://docs.astro.build/en/guides/content-collections).
1616+1717+:::note
1818+This article arose from a suggestion by [Sarah Rainsberger](https://github.com/sarah11918) and highlights a feature contributed by [HiDeoo](https://github.com/HiDeoo) - all code examples are also by HiDeoo.
1919+:::
2020+2121+## The need for snippets
2222+2323+Astro supports [schema validation](https://docs.astro.build/en/guides/content-collections/#defining-the-collection-schema) for your frontmatter fields in Markdown and MDX files. Therefore, many content files of your collections will have the same structure between the code fences (`---`). If you are tired of typing the same frontmatter fields over and over again, you can create a code snippet that will automatically generate the basic structure of the desired frontmatter while letting you conveniently edit the fields with `TAB ⇥` inputs.
2424+2525+## Creating a snippet
2626+2727+You can create global snippets which can be scoped to multiple languages or language-specific snippets. Since we want the frontmatter snippet in Markdown _and_ MDX files, we will create a global snippet under `Code/User/snippets/markdown.code-snippets` with the scope `markdown,mdx`. Follow the instructions in the [official documentation](https://code.visualstudio.com/docs/editor/userdefinedsnippets#_create-your-own-snippets) for the correct steps for your Operating System.
2828+2929+Here is an example of how your snippet could look like. You can freely adjust the `body` or `prefix` as you see fit:
3030+3131+```json title="Code/User/snippets/markdown.code-snippets"
3232+{
3333+ "Add Markdown frontmatter": {
3434+ "scope": "markdown,mdx",
3535+ "prefix": "ffmt",
3636+ "body": [
3737+ "---",
3838+ "title: $TM_FILENAME_BASE",
3939+ "description: The description",
4040+ "---",
4141+ "",
4242+ "## ${1:Heading}",
4343+ "",
4444+ "$0"
4545+ ],
4646+ }
4747+}
4848+```
4949+5050+The flexibility of snippets allows you to create powerful and bespoke productivity boosters. You can enhance the basic configuration from above with the specific frontmatter fields you need, change how the title gets generated, and more.
5151+5252+## Using the snippet
5353+5454+Create an empty Markdown (`.md`) or `.mdx` file. Start typing `ffmt` and press `TAB ⇥` to trigger the snippet. If you do not see any suggestions, you can manually trigger them with `Ctrl + Space` and select the `"Add Markdown frontmatter"` snippet. Depending on your exact configuration, you can now tab through the fields to edit them to your current use case. For example the snippet from above allows you to directly edit the heading and then jumps to the content. The title field of the frontmatter will be set to the file name without its extension.
5555+5656+
5757+5858+Read more tips and tricks for working with Astro and Starlight on [HiDeoo's blog](https://hideoo.dev/notes).
+9
src/content/docs/credits.mdx
···262262 usedOnUrl="/blog/starlight-sidebar-whitespace"
263263 />
264264 <ImageCredit
265265+ image="/public/blog/starlight-vscode-snippets.jpg"
266266+ title="Brown and White Cardboard Box"
267267+ author="Evelyn Clement"
268268+ authorUrl="https://unsplash.com/@e_clement"
269269+ sourceUrl="https://unsplash.com/photos/brown-and-white-cardboard-box-TgUwEK-RNUQ"
270270+ usedOn="How VS Code Snippets can improve your workflow in Starlight"
271271+ usedOnUrl="/blog/starlight-vscode-snippets"
272272+ />
273273+ <ImageCredit
265274 image="/public/blog/tags/mindspace.jpg"
266275 title="Brown and White Water Splash"
267276 author="Pawel Czerwinski"