Snippets appear for selection as you start typing, and the editor will paste in the entire content of the snippet.
Snippets in VS Code |
VS code snippets also have the ability to focus the cursor, ready for typing.
It's very closely related to code completion concepts, applied in VS Code with Intellisense. Vito on Twitter suggested perhaps these should be incorporated into intellisense instead of snippets. I think perhaps that might be a personal choice.
I found following the guide useful in getting started
https://code.visualstudio.com/docs/editor/userdefinedsnippets
And I thought I'd start with the Logger template, since I've finally converted.
I quickly ended up in the deep end, but swimming well. In a few strokes, I can add this entire block of text, with the three instances of the procedure name highlighted, ready to type over. That's pretty cool.
This took 5 keystrokes |
I figured a few variations of the entire text would be useful, so now as I type "log", I can tab, then start typing my log text.
The first few commands at the start of a procedure form another snippet, with the parameter name ready to type.
If I'm going to logger, I'm saving some typing... |
I extended this to include two parameters, and as you tab out of the first, the second two 'tabstops' are highlighted.
With all the magic going on by Adrian Png et al, I was a little surprised someone hadn't already published something for Logger.
Find my snippets JSON on Github.
Others on Twitter suggested they might send through a few examples they use, I was going to wait for some more inspiration.
The trickiest bit was escaping the dollar signs for plsql_unit. Thanks Stack Overflow.
Perhaps this set of JSON could be transformed into the Intellisense format. That would make an interesting SQL exercise...
Very cool! Can't wait to try it. Thanks!
ReplyDeleteA few weeks in, this is awesome. I can't wait to expand it to include other stuff.
ReplyDeleteI have a whole bunch of JavaScript one-liners I'd like to work on soon.