This VS Code trick can save your time!!

This VS Code trick can save your time!!

·

2 min read

Hello everyone, In this article i will be explaning about how to create your own Boilerplate for any programming language. I will ensure that by reading article you are going to make your own Boilerplate .

Let's deep dive in to our todays article !

What's a Boilerplate Code?

While coding, a piece of code that you have to use in every program mostly in every programming language. So, instead of manually typing code in the editor, we create a code-snippet so that that part of code is easily entered without typing it manually.

Boilerplate or a code-snippet are solution provided by IDEs like VS Code, where a certain piece code can be called within a program by typing prefix names.

Let's create

I am going to create a Boilerplate for C++

Step 1: Locating C++ JSON file for adding the snippet

  • Open your VS Code and click on the settings button in the bottom-left corner. Screenshot 2021-08-03 215623 (2).png
  • Click on User Snippets Screenshot 2021-08-03 210228 (2).png

  • Search for the Programming language for which you want to add boilerplate Screenshot 2021-08-03 210429 (2).png

Step 2: Adding the code to the .JSON file

  • You will get something like this when you open .JSON file Screenshot 2021-08-03 210526 (2).png

  • Remove the code below example and add this

    "boilerplate": {
          "prefix": "boilerplate code", //The prefix can be any random name
          "body": [
              "#include<iostream>" ,
              "using namespace std;" ,
              "int main()" ,
              "{" ,   
              "  $1" ,
              "  return 0;" ,
              "}"
          ],
          "description": "Log output to console"
      }
    

Screenshot 2021-08-03 211952 (2).png

  • After making changes to .JSON file press Ctrl+S to save the changes.

Step 3: Nothing more just use it your program

  • Create a New C++ file. Now Type the prefix .

  • VS Code automatically suggests while you are typing the prefix name . Screenshot 2021-08-03 211845 (2).png

  • Press ENTER.

Screenshot 2021-08-03 211928 (2).png

I hope you have found this article helpful :)

Wanna get connected! Find me on Twitter

Did you find this article valuable?

Support Manideep by becoming a sponsor. Any amount is appreciated!