Senger CodeLab 🚀

VS Code - Add a new file under the selected working directory

September 29, 2026

📂 Categories: Programming
VS Code - Add a new file under the selected working directory

Navigating your development environment efficiently is crucial for productivity, and for millions of developers, Visual Studio Code (VS Code) is the editor of choice. A fundamental task in any project is creating new files, and knowing the quickest, most reliable ways to add a new file under the selected working directory in VS Code can significantly streamline your workflow. Whether you’re setting up a new component, adding a configuration file, or simply jotting down notes related to your project, VS Code offers several intuitive methods. This guide will walk you through each approach, ensuring you can create files precisely where you need them, enhancing your project’s organization and your overall development speed. Mastering these techniques is key to a fluid and frustration-free coding experience within your VS Code workspace.

Why Efficient File Management in VS Code Matters

Effective file management goes beyond mere organization; it’s a cornerstone of productive software development. In VS Code, where developers spend countless hours, the ability to quickly and accurately create files directly impacts workflow efficiency. A well-structured project with logically placed files not only makes navigation easier for you but also improves collaboration within a team, as everyone can understand the project’s architecture at a glance. Poor file management, conversely, can lead to “dependency hell,” wasted time searching for misplaced code, and a higher risk of introducing bugs.

Beyond individual productivity, the integrity of your project’s structure is vital for its long-term maintainability and scalability. When you consistently add a new file under the selected working directory using best practices, you contribute to a clean codebase that is easier to debug, refactor, and expand upon. This attention to detail from the start prevents technical debt and ensures that your development process remains smooth, even as the project grows in complexity. VS Code provides powerful tools to enforce good habits, making it simpler to keep your workspace tidy and your projects on track.

The Primary Methods to Add a New File in VS Code

VS Code offers a variety of ways to create new files, catering to different preferences and scenarios. From visual interactions within the explorer to keyboard-driven commands, understanding these methods empowers you to choose the most efficient approach for your current task. Each technique is designed to help you quickly add a new file under the selected working directory, ensuring your project structure remains intact and logical.

Method 1: Using the File Explorer

The File Explorer is perhaps the most intuitive way to manage files and directories in VS Code. Located on the left sidebar, it provides a visual representation of your workspace. You can easily navigate through folders and create new items with just a few clicks. This method is ideal for beginners or when you need to visually confirm the file’s location.

To add a new file under the selected working directory using the File Explorer, follow these simple steps:

  1. Open VS Code and ensure your desired project or folder is open in the workspace.
  2. Click on the “Explorer” icon (the two overlapping sheets of paper) in the Activity Bar on the far left to open the File Explorer pane.
  3. Navigate to the parent directory where you wish to create the new file.
  4. Hover over the desired folder or the empty space within the Explorer pane. You’ll see icons appear: “New File” (a document with a plus sign) and “New Folder” (a folder with a plus sign).
  5. Click the “New File” icon. A text input field will appear, allowing you to type the new file’s name, including its extension (e.g., index.html, styles.css, script.js).
  6. Press Enter to finalize the file creation. The new file will immediately appear in the specified directory and open in the editor pane.

This method is straightforward and provides immediate visual feedback, making it excellent for ensuring the file is placed precisely where intended within your project’s hierarchy. For more details on the File Explorer, you can refer to the official VS Code documentation on the Explorer.

Method 2: The Command Palette

For those who prefer a keyboard-driven workflow, the Command Palette is an incredibly powerful tool. It allows you to access virtually all VS Code commands, including file creation, without touching your mouse. This method is often faster for experienced users once they memorize the relevant commands or shortcuts.

To utilize the Command Palette to add a new file under the selected working directory:

  • Press Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (macOS) to open the Command Palette.
  • Type “new file” into the input field.
  • Select “File: New File” from the suggestions. This will open a new, unsaved file in the editor.
  • To save this file into your desired directory, press Ctrl+S (Windows/Linux) or Cmd+S (macOS). The “Save As” dialog will appear, allowing you to navigate to your selected working directory and provide a file name.

An even quicker way, especially for creating a file directly within a specific path, is to use the “Go to File” command, which doubles as a file creator. If you need to quickly add a new file under the selected working directory, press Ctrl+P (Windows/Linux) or Cmd+P (macOS). In the input field, type the full path and name of your new file relative to your workspace root (e.g., src/components/MyComponent.js). If the path or file doesn’t exist, VS Code will prompt you to create it. This method is highly efficient for targeted file creation.

Method 3: Using the Integrated Terminal

For developers accustomed to command-line interfaces, the integrated terminal in VS Code provides a robust way to create files using shell commands. This method is particularly useful when you need to create multiple files, or when scripting file generation as part of a larger task. The terminal allows you to leverage standard operating system commands directly within your development environment.

To add a new file under the selected working directory using the integrated terminal:

  1. Open the integrated terminal in VS Code by going to Terminal > New Terminal or by pressing Ctrl+ (backtick).
  2. Ensure you are in the correct working directory. You can navigate using commands like cd folder_name or cd ...
  3. Once in the desired directory, use one of the following commands:
    • For Linux/macOS: touch new_file_name.extension (e.g., touch script.js)

    • For Windows (PowerShell): New-Item new_file_name.extension -ItemType File (e.g., New-Item config.json -ItemType FileQuestion & Answer :
      I’m trying to get a shortcut to add a new file under my current working folder. So I navigate to the explorer using Cmd+Shift+e and when I get to the folder I want to create a new class I do Cmd+n which creates me a new file but is not saved anywhere (I’m trying to get a similar behaviour to what ReSharper does for instance).

      Is there any other shortcut to get the file created under the folder you have the focus in the explorer? Essentially I could like to get the text box to fill in the name then the file gets automatically saved so that I don’t get the prompt later on.

      I’m using for reference the following page: https://code.visualstudio.com/docs/customization/keybindings

      The cmd+n command is by default bound to workbench.action.files.newUntitledFile but what you want is the command explorer.newFile which by default is not bound to a shortcut.

      Edit shortcuts file

      Hit Cmd+Shift+p type key and hit enter on Preferences: Open Keyboard Shortcuts (JSON)

      This will open keybindings.json file which stores custom keybindings specified by the current VS Code user.

      Enter the following in the custom bindings file (presumably you need to enter cmd+n instead of ctrl+n but I’m on windows so can’t test

      [ { "key": "ctrl+n", "command": "explorer.newFile" } ] 
      

      If you want to only have this apply when the explorer is focused you can add a when condition:

      { "key": "ctrl+n", "command": "explorer.newFile", "when": "explorerViewletFocus" } 
      

      This way when any other component is focused pressing Ctrl+n will execute the default new file command

      Edit using shortcuts UI

      Hit Cmd+Shift+p type key and hit enter on Preferences: Open Keyboard Shortcuts

      This will open up the keyboard shortcut preferences UI.

      Type explorer.newFile in the search to find the new file command, double click it to bring up the shortcut capture modal and press the key combination you want to associate with this command.