Today’s weekend programming lesson we covered how to save code snippets in a code editor, such as Sublime Test 3 (ST) and Visual Studio Code (code).
🙂 You can save these chunks of code so next time you wouldn’t have to type it again.
Until NeuralLink or other developments that can help us bypass typing all together, we want to find ways to save ourselves time from typing code. Using snippet is a must for children, who may not be great at typing. Here is how to do it in Sublime Test 3 (ST) and Visual Studio Code (code).
Tools – > Developer -> New Snippet.
😎 Shift + Control + F: to search for a string in your folder (perhaps the name of the snippet you saved).
💡Write the snippet that can be used by the code editor:
Snippets are json files. Use this ➡ web app, or some packages, or write json if you prefer to put the code into the json format.
Explaining .json snippet in VS Code:
- The first set of “” encloses the name of the snippet (call it anything you like).
- Prefix defines a prefix used in the IntelliSense drop down. For example, if you have a snippet for plotting, you may want to prefix it with “plot”.
- body is the snippet content.
- Note that: $1, $2 for tab stops
- Description is the description. When you start typing the prefix of a snippet, its description will come up.
By the way, to quickly see what are the keyboard shortcuts are available in VS Code:
Ctrl + Shift + p