I wanted to know if it is possible to trigger a user defined custom snippet when I create a file in vscode.
I started learning Golang recently and noticed that there is some boilerplate code that goes into creating the main.go
file.
So I created my custom snippet for it and now now I can trigger the snippet manually and save me some keystrokes of typing.
I wanted to go one step further, so that whenever I create a new file named main.go
from within VsCode, it should automatically fire that snippet and insert the biolerplate code for me, without me having to manually trigger the snippet.
Is this even possible ?
Check out this extension: Auto Snippet:
With this in your settings.json:
"autoSnippet.snippets": [
{ "pattern": "**/main.go", "snippet": "main-go-template" },
],
[Note that the example settings in the extension docs has a few syntax errors - use my example above - I have filed an issue with the creator.]
And then your snippet
"main-go-template": {
"prefix": "zz",
"body": [
... // you can use tabstops and transforms just like regular snippets
]
"description": "javascript template"
}
Then creating a new main.go
file or opening an empty one should trigger the snippet.
It is a good idea to reload vscode whenever you make a change to this extension's settings.
Here is a demo of a gulpfile with common boilerplate:
Also see this extension https://marketplace.visualstudio.com/items?itemName=bam.vscode-file-templates
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With