I did a
poll recently during one of my sessions – and I was surprised that about half
of the people don’t regularly use “snippets” in VSCode.. .
some of you probably know that I’m a big fan of snippets. Whoever has joined one of my sessions of the
last couple of years where I was talking about VSCode, or was working with
VSCode .. most probably, I was talking about, showing or using snippets.
I can’t live my life in VSCode without snippets. It would be so much less efficient .. . VSCode wouldn’t be much more than a notepad
that is hooked up with Source Control in that case.
2017, I even spent quite some time in my session on NAVTechDays about snippets. I’ll share the session at the end of this
How to manually create snippets?
would be able to explain you how to manually create snippets – but I
won’t. Because it is actually already
beautifully explained on the documentation section of VSCode here: https://code.visualstudio.com/docs/editor/userdefinedsnippets
user defined snippets …:
need to know is on the page mentioned above, and you’ll get going with snippets
in no time, I promise you!
more :-). I have been creating lots of
snippets in my
extension. I admit, I copied
Microsoft’s snippets and improved them – but I also have created lots of new
snippets. Ones that I use a lot in terms
of “design patterns”, but also for implementing code that I’m not
used to, and don’t want to forget (like the assisted setup). If you install my “CRS AL Language
Extension”, you’ll recognise my snippets with “waldo” in the suffix:
if you don’t want to work with my snippets, you can disable them by a simple
might wonder, you can disable Microsoft’s snippets as well ;-)).
Tools that can help you to create snippets
recently was pointed to this tool: https://snippet-generator.app/ . When you are creating your
VSCode snippets, simply paste the text that you want to convert to a snippet to
this tool, and you immediately get it converted to a JSON representation for a
VSCode snippet. I tremendously speeds up
the creating of a snippets from minutes to seconds ;-).
other hand, there is another tool that you can install in VSCode: the snippet-creator. It basically gives you a command that will
convert your selected text into a user-snippet of the language of your choice:
you prefer – both work very nice :-).
Some questions I get a lot
Where are snippets stored?
The user-defined snippets that you create, are stored here: %USERPROFILE%\AppData\Roaming\Code\User\snippets.
The snippets that come from an extension, are stored here: %USERPROFILE%\.vscode\extensions\<extensionname>\snippets
Can I disable snippets?
no. You can’t in any decent way (that I
know of) disable snippets. I know I was
talking about a setting in my extension, and yes, that’s a way, but it’s not a
decent way ;-).
what I do in that extension, is simply rename the “snippets” folder
to “snippets-disabled”. That
way, the extension is not able to find the snippets, and won’t show them
anymore. The downside of this is that it
will give errors in the background because it’s not able to find the snippets
really noticeable, but they are there… .
Can I change snippets?
again. To be fair: you CAN change a
snippet in the extension folder, but do know that when the extension is
updated, it basically is going to overwrite the snippets … and you lost your
modification. So in my opinion, that’s
not an option.
it! Hope you’re into snippets and this
blogpost was completely useless. If not,
at least I hope this got you triggered a bit ;-)! The only thing left for me is to share the
NAVTechDays session I was talking about earlier: