If you're someone who works with code regularly, you know how valuable code snippets can be. They can save you time and effort by providing a quick way to insert frequently used code into your projects.
With ChatGPT, you can easily turn code chunks into VS Code snippets, without having to enter them line by line in the snippets.json file yourself.
Works turbo fast in 4 steps… 🏎️
0) Open ChatGPT
First, open ChatGPT in your browser.
1) Provide a Code Chunk
Once you're in ChatGPT, provide the code chunk you want to turn into a snippet.
In my case, it was this mermaid graph:
graph LR;
A((Start)) --> B(Text Lowercase);
B --> C(Remove Special Characters);
C --> D(Remove Whitespace);
D --> E((End));
2) Request Snippet Conversion
Next, request that ChatGPT converts your code into a VS Code snippet. You can do this by asking something like "Can you turn this code chunk into a VS Code snippet?" or "How can I create a VS Code snippet from this code?"
Work in multiple steps. First ask for the snippet itself, then ask for add-ons, such as prompting for creating the labels of the graph as a variable.
3) Open Snippet file in VS Code
Press cmd + shift + p and open the snippet file corresponding to your programming language. Paste in the snippet.
4) Make sure it works.
ChatGPT can be a helpful tool and a workhorse for small, annoying, tasks like these. However, sometimes things go wrong. Make sure your snippet works and try it out.