How to create Custom Java Template/Snippet for Competitive Programming on VS Code.

Правка en4, от StormAlex, 2020-10-27 08:34:25

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.

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en5 Английский StormAlex 2020-10-27 08:35:38 0 (published)
en4 Английский StormAlex 2020-10-27 08:34:25 10 (saved to drafts)
en3 Английский StormAlex 2020-10-27 08:30:59 0 (published)
en2 Английский StormAlex 2020-10-27 08:30:20 99 Tiny change: 'unction.\n==================\n\n\n![ ]' -> 'unction.\n\n\n![ ]'
en1 Английский StormAlex 2020-10-27 08:20:08 2055 Initial revision (saved to drafts)