Code Templates
Type the first letters from the template name and trigger Content Assist. Code templates are preceded by the “Template” keyword.
Custom Templates
VS Code allows to create a custom code template, using the Code Snippets feature. Use the Snippets: Configure User Snippets command and choose a language for which the snippets should appear. Alternatively, you can choose to configure snippets at a workspace or global level.
For a comprehensive reference regarding custom snippets structure see the Code Snippets - Create your own snippets chapter in the official VS Code documentation.
To insert a custom code snippet, you can either use the content assist or the Snippets: Insert Snippet command.
Aside from using snippets, you can customize your code templates at a project level by using the following commands:
Create a New Code Template…
Edit Code Template…
Remove Code Templates…
Restore Removed Code Templates
Create a New Code Template
Use the Create a New Code Template… command to create a new code template:
Fields of the interface:
Name: The name of the template, displayed in the UI when using Content Assist
Description: A short description of the code template
Nature: Set for which project nature the template will be available. In single nature projects, this field is read-only (pre-filled with the project nature), otherwise it will contain a drop-down with all available natures
Pattern: This information will be inserted in the file when you choose the template from content assist
Edit Code Template
Use the Edit Code Template… command to edit an existing default / custom template.
Fields of the interface:
Name: The name of the template, displayed in the UI when using Content Assist
Description: A short description of the code template
Nature: Specifies for which project nature the template will be available (read-only)
Pattern: This information will be inserted in the file when you choose the template from content assist
Remove Code Templates
This command allows you to delete multiple code templates at the same time, by selecting them from the available list and pressing OK.
Restore Removed Default Code Templates
By calling this command, all the previously deleted code templates will be restored, allowing you to use them again.