Type Less With Code Snippets

Developers often face repetitive coding patterns, ranging from standard if/for structures to Go’s error handling or HTML boilerplates. This redundancy is inefficient and error-prone.

Snippets offer the optimal solution. When you type a short prefix (e.g., iffor), your IDE suggests a completion item that can be expanded into a predefined code template.

Build Your First Snippet

Code snippets are templates that simplify entering repetitive code patterns, such as loops or conditional statements.

To create a snippet:

  1. Press Ctrl + Shift + P to open the Command Palette and search for “Configure User Snippets”.
  2. Select snippets’ scope:
    • Global: Available in all file types.
    • Language-specific: Restricted to specific languages (e.g., JavaScript only).

After you select a snippet scope in VS Code, the editor will automatically create or open a corresponding JSON file: the file is named after the associated language (e.g., markdown.json for Markdown), while global snippets are stored in a dedicated global.json file.

A snippet file allows you to define multiple snippets. Each entry follows this structure:

PropertyDescription
"prefix"Trigger: The keyword(s) to activate the snippet.
"body"Content: The code array (supports multi-line).
"description"Tooltip: Optional hint shown in Completion menu.

Let’s start with 2 scenarios:

Sometimes, I insert animated images in WebM format into my Markdown posts. The standard HTML structure is a little bit verbose:

<video autoplay loop muted playsinline>  <source src="https://assets.vluv.space/job_control.webm" type="video/webm"></video>
I have a custom accordion element in my project. It accepts two placeholders: $1 for the title and $2 for the content.
<x-accordion>  <accordion-item title="What'you Name?">    My name is GnixAij.  </accordion-item></x-accordion>

So I write some snippet in my markdown.json with which I can easily insert HTML template by typing the prefix and accpet the completion result.

markdown.json
{	"animated_image": {		"prefix": "video",		"body": [			"<video autoplay loop muted playsinline>",			"  <source src=\"$1\" type=\"video/webm\">",			"</video>"		]	},	"Accordion": {		"prefix": ["x-accordion", "accordion"],		"body": [			"<x-accordion>",			"  <accordion-item title=\"$1\">",			"    $2",			"  </accordion-item>",			"</x-accordion>"		],		"description": "Accordion custom element with expandable items"	}}

One Definition, Multiple editors.

Nowadays, numerous forks of VS Code have emerged, including Cursor, Windsurf and Trae, which makes maintaining code snippets across different editors quite a hassle. Different editors store snippets in their own default directories as shown below:

EditorSnippets Folder
VSCode/Cursor/Trae<UserDataFolder>/User/snippets[1]
NeoVim using blink.cmp~/.config/nvim/snippet [2]

Here’s my approach to unified snippet maintenance (you can refer to my article on dotbot for the full details): I store all snippet files centrally in <dotfiles_folder>/path/to/snippets directory, then create symbolic links for each editor that point to this directory:

$ ls ~/.config/nvim `~/Library/Application Support/Code/User/` --long | where type == symlink | select name target╭───┬───────────────────────────────────────────────────────────────────┬──────────────────────────────────────────────────────────────────╮ #                                name                                                              target                              ├───┼───────────────────────────────────────────────────────────────────┼──────────────────────────────────────────────────────────────────┤ 0  /Users/gjx/.config/nvim/snippets                                   /Users/gjx/Projects/dotfiles/application/vscode/snippets          1  /Users/gjx/Library/Application Support/Code/User/keybindings.json  /Users/gjx/Projects/dotfiles/application/vscode/keybindings.json  2  /Users/gjx/Library/Application Support/Code/User/settings.json     /Users/gjx/Projects/dotfiles/application/vscode/settings.json     3  /Users/gjx/Library/Application Support/Code/User/snippets          /Users/gjx/Projects/dotfiles/application/vscode/snippets         ╰───┴───────────────────────────────────────────────────────────────────┴──────────────────────────────────────────────────────────────────╯

This way, I only need to maintain a single copy of snippets for all editors without redundant work.

Read Also


  1. The  user data folder’s location is dependent on the platform: %APPDATA%/Code for windows, ~/.config/Code for Linux and ~/Library/Application Support/Code for macOS ↩︎

  2. Blink uses the vim.snippet API by default for expanding and navigating snippets. The built-in snippets source will load friendly-snippets, if available, and load any snippets found at ~/.config/nvim/snippets/.Snippets | Blink Completion (blink.cmp) ↩︎

Type Less With Code Snippets

https://vluv.space/vscode_snippets/

Author

GnixAij

Posted on

2026-02-05

Updated on

2026-02-23

Licensed under