When you realized you have typed some codes 100 times, you should save it as a code snippet. For example, I made a snippet for hapi route, when I type
hapi:route it will trigger intellisense and then generate the router boilerplate code for me.
It hard to write and maintain the VS Code code snippet because the code snippet was in a JSON file. So I wrote a tool to generate this JSON file for me, and I need only write the snippets in a folder.
The tool called
snp (which means snippet). You can install it by curl:
$ curl -sf https://gobinaries.com/djyde/snp | sh
It is written in Go so it can run on many platforms, include Windows.
You can create a folder to organize all your code snippets now:
$ mkdir snippets $ cd snippets
Then you can create a file with
.snp extension. The file name would become the trigger text.
For example, I want to write a hapi route snippet, now I
$ touch hapi:route.snp
As you can see,
.snp file is just a file that contains a front matter and the code snippet.
If you are not familiar about the VS Code code snippet syntax, please see https://code.visualstudio.com/docs/editor/userdefinedsnippets#_snippet-syntax
snp -u, now go to VS Code and type
hapi:route, you will see the magic:
You can now use
snp to manage your VS Code NATIVE code snippets, instead of using some code snippet manager apps that only help you copy and paste.
See more on https://github.com/djyde/snp
my personal snippets: https://github.com/djyde/snippets