Thursday, July 4, 2024
HomeData ModellingData Structure & AlgorithmCreation and Utilisation of Custom Snippets for Competitive programming in VScode

Creation and Utilisation of Custom Snippets for Competitive programming in VScode

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

Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!

Ted Musemwa
As a software developer I’m interested in the intersection of computational thinking and design thinking when solving human problems. As a professional I am guided by the principles of experiential learning; experience, reflect, conceptualise and experiment.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments