Skip to content
VS Code user snippets for documentation

Modularize Content in VS Code (for DOCS)

Jannic Weidel
Jannic Weidel March 24, 2022
4 min read

As a technical editor, I work a lot with text. Technical editors write documentation, gather information for release notes or change logs and the like. The layout is often the same, so it is worth to modularize the structural layout patterns (like tables, notes or even whole documents) to save time and be more productive. Visual Studio Code allows you to create so called User Snippets which can be used to create templates for repeating contents/layouts.

To open the user snippet file (in which you define one or more templates), do the following:

  • Create a new file (example.md) in Visual Studio Code.
  • In VS Code, click on Settings > User Snippets (bottom left corner).

VS Code's bottom-left gear menu open with User Snippets highlighted in the list

A new window in the middle of the screen is displayed.

Snippet file picker listing markdown.json at the top followed by every other language's snippet file

  • Click on markdown.json to open the user snippet file for the file extension “.md”.
  • The code of the markdown.json file is displayed in your editor.

Freshly opened markdown.json file containing only VS Code's default commented-out example snippet

  • Add the following code to this file (see screenshot above, at line 15):
"Table (2 columns)": {
  "prefix": "Table (2 columns)",
  "body": [
    "|**${1:Header column 1}**|**${2:Header column 2}**|",
    "|--|--|",
    "|${3:Line 1 column 1}|${4:Line 1 column 2}|",
    "|${5:Line 2 column 1}|${6:Line 2 column 2}|",
    "|${7:Line 3 column 1}|${8:Line 3 column 2}|",
    "|${9:Line 4 column 1}|${10:Line 4 column 2}|",
    "|${11:Line 5 column 1}|${12:Line 5 column 2}|",
    "|${13:Line 6 column 1}|${14:Line 6 column 2}|",
    "|${15:Line 7 column 1}|${16:Line 7 column 2}|",
    "$0"
  ],
  "description": "Table with 2 columns and 7 lines"
},

Press CTRL + S to save the markdown.json file.
This extends your user snippets for markdown files with a template for a table with 2 columns and 7 lines.

markdown.json after adding the new Table (2 columns) snippet definition below the default example

  • Switch to your markdown file and press CTRL+Space to display the available user snippets.

example.md with the CTRL+Space snippet suggestion list open, showing the new Table (2 columns) snippet at the top

You now have the “Table (2 columns)” template in your user snippets.

  • Press Enter to insert the snippet in your example.md file.

example.md editor showing the inserted table snippet next to its live markdown preview with the rendered two-column, seven-row table

Press Ctrl + K , … V to open the preview of the example.md file.

Press Tab to jump to the different locations in the table.

Feel free to add/create new user snippets (the four dots are spaces -> indent):

markdown.json snippet code with numbered callouts 1 through 8 marking the parts explained in the table below, such as the prefix, body, and jump stops

No. Description
1 Enter a unique description here. The entered text is displayed at the right side of the User Snippet menu (CTRL + Space in the example.md file).
2 The Prefix is the "name" of the user snippet. Start typing the name of the snippet in the example file and stop halfway (e.g. type “Tabl” and press CTRL + Space) and VS Code will propose your snippet with the corresponding prefix value.
3 In the "body" you define the lines (separated with a comma at the end) which are added when selecting the user snippet from the menu.
4 With “${No:____}” you can add jump stops. After you have added the user snippet to your example file you can "jump" to each stop with the Tab button. Please note: You should start with No. 1! $0 is already defined as the last jump stop → see 6.
5 Always end the lines in the body with a comma... otherwise the snippet won't work.
6 $0 ... this is the final jump stop. You get there once you have "tabbed" all stops.
7 Enter a description here. The description is displayed when you extend additional information about the user snippet. Snippet suggestion list with the description panel expanded on the right, showing 'Table with 2 columns and 7 lines (User Snippet)' and a preview of the body
8 Close the whole user snippet and add a comma at the end.

User snippets also work for other coding languages, just give it a try... it will save you so much time. If you have any questions or need help with user snippets for a different coding language, just drop me a PM at LinkedIn.

Have a nice day,

Jannic

Related posts

▸ All posts
Microsoft PowerToys productivity tools for Windows

Microsoft PowerToys: Free Utilities for Windows

January 24, 2023 · Daniel Gorski

Microsoft PowerToys brings FancyZones, PowerRename, Color Picker, File Locksmith and more to Windows – a free, open-source set of utilities.

Read More
Read More: Streamline your Windows experience with Microsoft PowerToys
Using OpenAI to write AL code for Business Central

Writing Business Central AL Code with ChatGPT

December 03, 2022 · Daniel Gorski

How OpenAI's ChatGPT helps Business Central developers write AL code – from a table design to a full page, and what you still need to adjust.

Read More
Read More: Writing code with a text-based AI for Business Central
Set up a custom BC25 repository

BC25 Base App Repo: Find All References in AL

September 19, 2024 · Daniel Gorski

Build your own BC25 repository from the base app, platform packages and assemblies so Find All References works across Microsoft's code in VS Code.

Read More
Read More: Increase Your DEV productivity with your own BC25 REPO