A VS Code extension that allows you to create new files from templates via a context menu on folders.
Author: Debashish Sarker
Repository: https://github.com/deba1/file-template
- Create File from Template: Right-click on any folder in the explorer and select "Create File from Template" to create a new file from a saved template.
- Create Template from File: Save any file as a template for future use.
- Edit Templates: Open and edit existing templates.
- Delete Templates: Remove templates you no longer need.
- Template Variables: Use variables in templates that get replaced when creating files (e.g.,
{{filename}},{{date}},{{year}}).
- Open the file you want to use as a template.
- Run the command "Create Template from File" (via Command Palette:
Ctrl+Shift+P/Cmd+Shift+P). - Enter a name for the template.
- Optionally enter a description.
- Right-click on a folder in the Explorer.
- Select "Create File from Template".
- Choose a template from the list.
- Enter the file name.
- If the template contains variables, you'll be prompted to enter values for them.
Templates support variables that are automatically replaced:
{{filename}}- The file name (without extension){{date}}- Current date{{time}}- Current time{{datetime}}- Current date and time{{year}}- Current year{{month}}- Current month (01-12){{day}}- Current day (01-31){{variableName}}- Custom variables (you'll be prompted for values)
- Edit Template: Run "Edit Template" command to open a template for editing.
- Delete Template: Run "Delete Template" command to remove a template.
- Export Templates: Run "Export Templates" command to export all templates to a folder. This creates a folder with all template files and a
metadata.jsonfile. - Import Templates: Run "Import Templates" command to import templates from an exported folder. You can choose to overwrite existing templates or skip conflicts.
- Template Name: The name you give to the template when creating it (e.g., "React Component")
- File Name: The default file name when creating a file from the template. This defaults to the original source file name when the template was created.
You can use different names for templates and files. For example:
- Template name: "React Component Template"
- Original source file:
Component.tsx - When creating a file, the default name will be
Component.tsx, but you can change it to any name you want.
You can export your templates to share them with others or backup them:
- Export: Run "Export Templates" command. Select a folder where you want to export templates. A new folder will be created with all templates and metadata.
- Import: Run "Import Templates" command. Select the folder containing exported templates. If there are conflicts (templates with the same name), you can choose to:
- Overwrite: Replace existing templates with imported ones
- Skip Conflicts: Import only new templates, skip existing ones
- Cancel: Cancel the import operation
// {{filename}}.js
// Created on {{date}}
/**
* {{description}}
*/
class {{className}} {
constructor() {
// TODO: Implement
}
}
export default {{className}};When creating a file from this template, you'll be prompted to enter values for description and className. The default file name will be the original source file name when this template was created.
- VS Code 1.74.0 or higher
Templates are stored in the extension's global storage. They persist across workspaces.
Initial release of File Template extension.
MIT
Debashish Sarker
- GitHub: @deba1
- Repository: https://github.com/deba1/file-template