Reputation: 63
Is there some way to add a code snippet to a file when it is created based on the file type/extension. I want to add header guards when I created a new C++ header file. Example:
#ifndef DIRECTORY_FILENAME_H
#define DIRECTORY_FILENAME_H
#endif // DIRECTORY_FILENAME_H
I've already created a code snippet that adds this text, but I can't figure out how to add this automatically when a file is created.
Upvotes: 1
Views: 1667
Reputation: 67541
https://marketplace.visualstudio.com/items?itemName=Gruntfuggly.auto-snippet
Example:
autoSnippet.snippets: [
{ "pattern": "ut-*.cpp", "snippet": "ut-template",
{ "pattern": "*.h", "snippet": "header-template" },
{ "pattern": "*.cpp", "snippet": "body-template",
{ "language": "javascript", "snippet": "template", "commands":"[ editor.action.commentLine" ] }
]
Upvotes: 3