1

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.

1 Answer 1

3

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" ] }
]
Sign up to request clarification or add additional context in comments.

1 Comment

Go to Preferences: Configure User Snippets to configure snippets for this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.