How to create snippets in Sublime Text
In this article, we will discuss how to create snippets in Sublime text for Competitive Programming. In Competitive Programming, time is the most important key, and snippets give us functionality to not write the same code again and again and increase our performance in live contests.
To install Sublime Text, refer to this article.
Steps to make snippets in Sublime Text:
- Open Sublime Text:
- Go to Tools: Go to the Tools option and click on it.
- Go to Developer Option: Go to the developer option and click on New Snippet. A file will be open with some pre-written code.
- Edit file: A file will open after clicking on New Snippet. Now, remove the comments as shown below from this opened file.
- Add Code: Now, remove some pre-written code and write your own code in that.
- For Example, You can write any code in the above window. Below is the illustration of that:
- Set TabTrigger: It shows the keyword that anyone wants to use for this code. When that keyword triggered, the default code which is changed in the above steps will present there. So, First remove that pre-written keyword:
- Write a keyword that you want to use for this code. In my case keyword is gcd():
- Set Scope: Now, to set the scope, i.e., to use this snippet in which language. To set scope, first remove pre-written scope:
- Write the scope in which anyone wants to use this snippet. In the below case, the scope is C++:
- Save Snippet: Now, save the snippet with the extension. sublime-snippet:
- The snippet is ready to be used.
- Now open the file and type your keyword for the snippet. In my case, it is gcd(), So just write gcd and hit enter:
- And our code is present here: