📄 Auto File Templates
🚀 Fast, minimal file scaffolding for VS Code
Create new files pre-filled with templates — automatically or on demand.
Auto File Templates lets you define simple text templates and apply them:
- automatically when a new file is created
- manually via the command palette
- directly from the Explorer right-click menu (just like VS Code’s native “New File”)
No frameworks. No magic. Just smart defaults.
✨ Features
🧠 Automatic template insertion
- Applies a template only when a file is empty
- Never overwrites existing content
- Works with files created via:
- VS Code Explorer
- Command line (
touch, custom shell functions, etc.)
📄 Template matching rules
- By extension
index.html → html.template
main.py → py.template
- By full filename (no extension)
Dockerfile → Dockerfile.template
Makefile → Makefile.template
🖱️ Explorer right-click: “New file from template”
- Right-click a folder in the Explorer
- Choose a template
- Enter the filename inline (no system file dialog)
- File is created in place and opened with the template inserted
⌨️ Command palette support
- Create a new file from any template
- Choose destination using the native save dialog
🛠️ Fully configurable
- Custom template directory
- Plain text templates
- Supports VS Code snippet placeholders (
$TM_FILENAME, tab stops, etc.)
📦 Built-in Starter Templates
This extension ships with a small set of starter templates out of the box.
On first activation:
- A template directory is created (if missing)
- Default templates are copied once
- Existing user templates are never overwritten
You are free to edit, delete or add templates at any time
🚀 How It Works
Automatic mode (zero interaction)
- You create a new file (Explorer, CLI, script, etc.)
- VS Code opens the file
- If the file is empty:
- The extension looks for a matching template
- Inserts it as a snippet
- If no template exists → the file stays empty
Manual mode (on demand)
You can explicitly create a file from a template using:
- the Command Palette
- the Explorer context menu
📂 Template Resolution Rules
| File created |
Template used |
index.html |
html.template |
main.ts |
ts.template |
Dockerfile |
Dockerfile.template |
Makefile |
Makefile.template |
config.env |
env.template |
random.txt |
❌ none (empty file) |
Templates are optional — no template means no action.
Right-click a folder in the Explorer and select:
Flow:
1. Pick a template
2. Enter a filename (inline prompt)
3. File is created in the selected folder
4. Template is inserted automatically
This behaves similarly to VS Code's built-in New File action
⌨️ Command Palette
Flow:
1. Pick a template
2. Choose a location using the save dialog
3. File is created and opened with the template inserted
⚙️ Configuration
📁 Template Directory
Default location
Windows
$HOME/AppData/Roaming/Code/User/FileTemplates
Linux
$HOME/.config/Code/User/FileTemplates
macOS
$HOME/Library/Application Support/Code/User/FileTemplates
Custom template path
Override the default path in VS Code settings:
{
"autoFileTemplates.templatesPath": "C:/path/to/your/templates"
}
This extension provides several templates that you can put in your template folder and modify at will
📄 Template Naming Rules
Templates are plain text files named as:
<extension>.template
or
<filename>.template
Example
FileTemplates/
├── html.template
├── css.template
├── js.template
├── ts.template
├── py.template
├── Dockerfile.template
├── Makefile.template
├── README.md.template
✨ Snippet support
Templates are inserted using VS Code's snippet engine
You can use:
$TM_FILENAME
$TM_FILENAME_BASE
tab stops ($1, $2, ...)
Example:
/**
* File: $TM_FILENAME
*/
function main() {
$1;
}
🖥️ Recommended CLI Workflow
This extension pairs perfectly with command-line file creation (touch, start, helper functions)
Example bash helper:
new() {
for filepath in "$@"; do
mkdir -p "$(dirname "$filepath")"
[ ! -f "$filepath" ] && touch "$filename"
code "$filepath"
done
}
Usage:
new src/index.html
new Dockerfile
new scripts/main.py
Templates are applied automatically when VS Code opens the file
🛡️ Safety & Design Principles
✅ Templates are applied once
✅ Existing files are never modified
✅ No background watchers or polling
✅ No assumptions about frameworks or tooling
✅ Plain files, easy to understand and customize
⚡ Activation
The extension activates on:
- VS Code startup
- File creation
- File opening
Lightweight and low-overhead, no manual setup required
🧩 Compatibility
- ✅ Windows
- ✅ Linux
- ✅ macOS
- ✅ VS Code Stable & Insiders
🤝 Contributing
Contributions are welcome:
- Template ideas
- Bug reports
- Feature requests
- Code improvements
Open an issue or pull request on the repository
📄 License
MIT License
🙌 Philosophy
This extension is built for developers who value:
- Speed
- CLI-friendly workflows
- Minimal configuration
- Predictable behavior
- Smart, optional automation