StormAlex's blog

By StormAlex, history, 4 years ago, In English

Reading time : 3 min and Setup time: 5-10min

How to create Custom Java Snippets for Competitive Programming on VS Code.

Many of you might wonder how some people write 100 lines or 200 line solutions to some problems so quickly. On the other hand, you might be taking 30 min to 45 min to write the same code. So we are going to discuss how you can add Java templates/snippets to your VSCode so that you could also use your own custom templates and write solutions quicker.

Step 1: Open your VS Code.

Step 2: Press Ctrl + Shift + P

Step 3: Search "Configure User Snippets".

Step 4: Select "New Global Snippets file"

Step 5: It will prompt you to type a name for your snippet. (ex: template)

Step 6: After the 5th step, it will create a "template.code" file, This is the file where you will add your Java Snippet.

Page Overview:

Step 7: Now let's understand the file:- The file is broken down into 4 sections: (scope, prefix, body, description)

  • scope: This is where you specify your language(java, c++, javascript)
  • prefix: This is the prefix that you will type to trigger the template.
  • body: Your code will go here.
  • description: You can add a description of your template here.

Step 8: Here is a sample template that contains the main function and a gcd function.

Step 9: How to use this template you have created?

Just open an empty file, add extension .java and just type "gcd" and enter. The whole template will be loaded for you.

Template in action

I hope this tutorial has helped you. This technique can be used for any language. This is my first blog on Codeforces. Hoping to contribute more in the future. Thank You very Much.

  • Vote: I like it
  • +3
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
  Vote: I like it +3 Vote: I do not like it

https://snippet-generator.app/

Same thing is implemented in this website. Just paste your code to generate snippets. Supports VS Code , Sublime Text and Atom.