Rename a File, Folder or Workspace in Visual Studio Code

avatar
Borislav Hadzhiev

Last updated: Apr 6, 2024
4 min

banner

# Table of Contents

  1. Rename a File or a Folder in Visual Studio Code
  2. Rename a Workspace in Visual Studio Code
  3. Rename multiple Files at once in Visual Studio Code

# Rename a File or a Folder in Visual Studio Code

The easiest way to rename a file or a folder in VS Code is to:

  1. Right-click on the file or folder in Explorer.
  2. Select Rename....
  3. Give the file a new name and press Enter.

right click rename file

The same approach can be used to rename a folder. You simply have to right-click on the folder and select Rename....

Here is a short gif that demonstrates how to rename a file or a folder.

right click rename file

You can also use the F2 keyboard shortcut to rename a file or a folder.

Left-click on the file or folder in Explorer to select it and press F2.

rename file or folder using f2 shortcut

Note that in order for you to rename a file or a folder, it has to be saved.

If you haven't saved the file yet, you won't be able to rename it as it doesn't exist on the file system.

If you just created the file in VS Code, press Ctrl + Shift + S (or Cmd + Shift + S on macOS) to save it.

press ctrl shift s to save file

Once you press Ctrl + Shift + S a dialog opens and enables you to name the file.

Once the file is saved to your file system, you can rename it as shown in the previous examples.

You can also save the file by clicking on File -> Save as in the top menu.

Note that you might have to press Alt to show the top menu on Windows and Linux.

click file save as

Once you click File -> Save as, a dialogue opens and enables you to save and name the file.

You can also trigger the Save as action using the Command Palette:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type save as and select File: Save as....

file save as

If you need to rename multiple files at once in VS Code, click on the following subheading:

# Rename a Workspace in Visual Studio Code

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type save workspace and select Workspaces: Save Workspace As....

save workspace as

Once you select the option, a dialogue window opens and enables you to save your Workspace into a file.

You can give your workspace a different name and click on the Save button.

rename workspace in vscode

Alternatively, you can click on File in the top menu and then click Save Workspace As....

click file save workspace as

Note that you might have to press Alt on Windows and Linux to show the top menu.

If you already have a .code-workspace file in your project, you can rename it by right-clicking on it in Explorer and selecting Rename....

right click workspace file and rename

Once you click Rename..., give the file a new name and press Enter to confirm.

Alternatively, you can left-click on the .code-workspace file and press F2 to rename the workspace.

rename workspace using f2

An alternative approach to rename a workspace is to edit your .code-workspace file and set a name property for each folder.

example.code-workspace
{ "folders": [ { "path": "/path/to/folder", "name": "new folder name" } ], "settings": {} }

The name property is used to set the display name for each folder in the workspace.

# Rename multiple Files at once in Visual Studio Code

If you need to rename multiple files at once in VS Code:

  1. Click on Extensions in the left sidebar.
  • You can also open the Extensions menu by pressing:
    • Ctrl + Shift + X on Windows or Linux.
    • Command + Shift + X on macOS.
  1. Type Batch Rename.

install batch rename extension

  1. Click on the Install button.

Make sure to install the Batch Rename extension from JannisX11 as shown in the screenshot.

Once the extension is installed:

  1. Select the files you'd like to rename in Explorer.

You can select multiple files by holding Ctrl (Cmd on macOS) and clicking on them.

select multiple files ctrl

If the files are one after the other, you can also left-click on the first file, press Shift and left-click on the last file.

select multiple files shift

  1. Once you've selected the files, right-click on one of them and click Batch Rename.

right click batch rename

  1. A new window opens where you can rename the multiple files at once.

rename multiple files at once

  1. Once you rename the files, save the .Batch Rename.txt file to complete the process.

Here is a short clip that demonstrates the process.

rename multiple files at once

I've also written an article on how to rename/refactor a variable name in VS Code.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.