How To Create Code Snippets in VS Code

Editor Ratings:
User Ratings:
[Total: 3 Average: 1]

A snippet is a small reusable source that can be reused again and again by calling it with a unique keyword. This eliminates the need typing source again and again when needed. You can simply insert it by typing the short keyword and save yourself some time.

This article covers a free extension to create code snippets in VS Code. The name of this extension is Snippet Maker and available in Visual Studio Marketplace. This extension is open source, you can access the source code of this extension at its GitHub page. The overall procedure of creating and accessing the snippets using this extension is simple and quick.

Also read: Free Decentralized code Snippet Manager with tags, Sharing, Embed code

How To Create Code Snippets in VS Code

To create code snippets with Snippet Maker, first, you have to install this extension in the VS Code. To do that, go to the Extension section in the VS Code and type the name of this extension(i.e. Snippet Maker). Then look for this extension in the results. You can identify it with its developer name(ziishaned) or its icon. Once you find the extension, click the install button to add it to the VS Code.

generate code snippets in VS Code

Note: You have to restart the VS Code to make this extension work.

Create Code Snippet

create code snippets in VS Code

Creating code snippets is simple with this extension. To create a snippet, first, select the code and press Ctrl+P. This opens a search bar at the top. In the search bar type “>snippet” and select SnippetMaker: Make Snippet command. After that, enter the following details(step-by-step) for the snippet:

  • Language: Select the programming language for the snippet.
  • Name: Type a name for the snippet.
  • Trigger: Assign a unique trigger keyword to the snippet.
  • Description: Add an optional description of the snippet.

When you finish this process, your snippet is saved.

Access Snippet

code snippets in VS Code

To access a saved snippet, simply type the trigger of that snippet and it will appear in the suggestions with all its details. You can tap or press Enter key on the snippet to use it in the editor.

Note that, you can access a snippet in its defined language only. For example, if you created a snippet for C++, you can only use it in CPP files. It can’t be accessible in other programming language files.

Closing Words:

Snippet Manager is a handy tool to easily make code snippets in VS Code and access them quickly. This saves you time and the hurdle of digging into snippet file.

Editor Ratings:
User Ratings:
[Total: 3 Average: 1]
Works With: VS Code
Free/Paid: Free

Leave A Reply


Get 100 GB FREE

Provide details to get this offer