If you’re just a beginner in programming trying to learn a new programming language or a professional programmer who works full-time writing codes, You always need to do a lot of coding. Each time you start a new project or a new file, You always need to start with a boilerplate.
Although boilerplates for some basic languages are included by default in VS Code Studio, there are no boilerplates for many languages. Even current boilerplates are insufficient for some users, as they may not contain all of the necessary codes.
You can make your own boilerplate for any language you’re learning by editing a custom code snippet. You can also make multiple boilerplates based on your needs.
Today, we’ll learn how to use VS Code to create a custom code snippet using the VS Code User Snippets option. There are a number of extensions that perform the same purpose, however installing one isn’t always recommended because it can slow down your machine because the more extensions you have, the more memory your VS code requires.
Let’s begin with user settings in VS Code Studio (which lied in the bottom left of the screen) and click on User Snippets.
After clicking on User Snippets, You should see something like this.
You need to select the snippet based on the file extension you’re working on. We’re going to create a snippet for C, So we’re going to click on c.json.
If you want to create a snippet that works on every file extension, You can create a snippet using a Global snippet file.
In the JSON file, You will see some comments in Curly brackets. This is where we will enter our snippets. However, As the file is in JSON, We need to enter the different structures, So we will use a snippet generator to generate a snippet for our code.
You can simply enter your C code in the snippet generator website and it will generate a snippet code for the JSON file.
Now You can copy the generated code in the JSON file. After adding the code in the JSON file, we need to add the name for our Code Snippet which is called prefix here.
The Snippet is used to call the snippet from our workspace, so make sure it is easy and doesn’t conflict with other common boiler plates.
After adding the prefix, You’re now ready to save some time writing some lame codes again and again. You can simply start with the boilerplate instead of writing a bunch of repeated codes and save some time for choosing the best wallpapers for programmers.
The boilerplates in VS Code can simply be triggered using the name of the boilerplate (Code Snippet), In this case, it is the prefix of the JSON file we just generated.
So that’s how we make a custom code snippet in Visual Studio Code Studio. Many people are unaware of custom code snippets in VS Code Studio; if you know someone who is unaware, tell them about the Custom Snippet as “Sharing is Caring.”