Open In App

Creation and Utilisation of Custom Snippets for Competitive programming in VScode

Improve
Improve
Like Article
Like
Save
Share
Report

Coding down the whole algorithm from scratch during the online contest can cost you plenty of time and may lead to a bad rank. There is no point in coding the same algorithm you have coded hundreds of times earlier. Why not utilize your previously coded implementations? You can do that by creating custom code snippets and summoning them just by a keyword whenever and wherever you need.

Code Snippets Creation:

  • Open folder where you code in VScode as shown in the below image. Here we will make a code snippet of the Rabin-Karp file and will summon it later in the test file.

Folder Structure

  • Install  Convert text/code to a snippet vs code extension from the marketplace by clicking the square box present in the left side-bar. This extension helps to create JSON files from code and this JSON file is required to make custom snippets in vs code.

VS Code Extension

  • Now,  open the command pallet using command ctrl+shift+p and type reload window in the pallet, and hit enter to reload the window.
  • Copy the code you want to make the snippet for and hit ctrl+shift+p and type convert to snippet in the pallet and hit enter. Fill in the details asked such as snippet title, description, and prefix. Choose your prefix carefully, It will be used to summon this code snippet.
  • Copy the JSON output displayed by extension.

JSON Output

  • Click on the setting wheel present at the bottom in the left side-bar. Choose the user snippet option and then choose the programming language of the snippet. Remove the existing comments and code and put the copy JSON in a curly bracket. You can make as many snippets as you want, just separate the two consecutive snippets JSON with commas.

Snippet JSON

Code Snippet Utilization:

  • Open a file (test.c++ in my case), type the code snippet prefix you assigned, and hit enter on suggestion. Your file will be populated with the corresponding code snippet.

Code Snippet Recommendation


Last Updated : 12 Mar, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads