Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Quick Add File (Shift+F2)

Recreates the Visual Studio Add New File (Shift+F2) experience in VS Code: press Shift+F2, type a relative path, and the file — including any missing folders — is created and opened immediately. No dialogs, no clicking through the explorer.

Usage

Press Shift+F2 (or right-click a folder in the Explorer → Quick Add File: New File...), then type:

Input Result
OrderService.cs Creates the file next to the active file
Services/Orders/OrderService.cs Creates the nested folders and the file
Models/Order.cs, Models/Customer.cs Creates multiple files at once
Docs/ Trailing slash creates a folder only
/src/Program.cs Leading slash is relative to the workspace root

The base folder is chosen the same way Visual Studio does it:

  1. The folder you right-clicked in the Explorer.
  2. Otherwise, the folder containing the active editor's file.
  3. Otherwise, the workspace root.

Existing files are never overwritten — they are just opened.

Templates

New files can start with content chosen by their extension. Built in for .cs:

namespace MyProject.Services.Orders;

public class OrderService
{
    // caret lands here
}

The namespace comes from the nearest .csproj walking up from the new file (<RootNamespace> if set, otherwise the project file name) plus the folder path below it. Files named IOrderService.cs get interface instead of class.

Add or override templates per extension in settings:

// settings.json
"quickAddFile.templates": {
  ".ts": "export class {name} {\n\t{cursor}\n}\n",
  ".razor": "<h3>{name}</h3>\n\n@code {\n\t{cursor}\n}\n",
  ".cs": ""   // empty string disables the built-in template
}

Placeholders: {name} (file name without extension), {fileName}, {namespace}, {type} (interface for I-prefixed names, else class), {cursor} (where the caret is placed after the file opens).

Install

npm install -g @vscode/vsce   # once
cd D:\Repos\quick-add-file
vsce package
code --install-extension quick-add-file-1.0.0.vsix

Or press F5 with this folder open in VS Code to try it in an Extension Development Host.

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages