Everyday Toolkit

How to Rename Files and Symbols in VS Code (Shortcuts & Refactoring)

Published 2026-07-27

Updated Jul 2026

Some links on this page are affiliate links. If you buy through them we may earn a small commission at no extra cost to you. We only recommend what we'd use.

Key takeaways
  • Press F2 in the Explorer tree to rename files instantly without taking your hands off the keyboard
  • Enable automatic import updates to prevent broken references across your project
  • Use Rename Symbol (F2 inside the editor) to update variables, classes, and functions workspace-wide
  • Guard against case-sensitivity bugs between Windows, macOS, and Linux when modifying filenames.
How to Rename Files and Symbols in VS Code (Shortcuts & Refactoring)
Photo: Michiel1972 (talk) 22:00, 24 January 2009 (UTC) (BY-SA) via Openverse

Renaming files in Visual Studio Code takes just a couple of keystrokes using the F2 shortcut in the Explorer panel, the context menu, or language-aware refactoring tools that automatically rewrite import statements across your codebase.

🛍 Ready to buy? Check current prices on Amazon for the picks in this guide.

The Quickest Ways to Rename Files in VS Code

You can rename any file in VS Code instantly by clicking the file in the Explorer sidebar and pressing F2. Alternatively, right-click the file and select Rename, or hit Enter on macOS while focused on the tree item. These methods immediately open an inline edit box right inside the file panel.

Navigating the file tree with mouse clicks slows down your coding flow over time. Keeping your hands on the home row gives you tighter control over project refactoring, especially when moving between several modules in a single session. VS Code gives you inline editing capabilities right inside the Explorer pane, so you don't have to pop open modal dialogs or drop into an external file manager.

Beyond changing the raw filename on your drive, modern web projects require updating the module references that point to that file. If you rename a component or utility script without updating its imports, your bundler or compiler throws missing module errors immediately. Setting up the right native shortcuts prevents those build breakages before they happen.

Using the F2 Key

Pressing F2 while a file is focused in the Explorer sidebar is the fastest built-in shortcut to rename files without leaving your keyboard. An editable input box appears directly over the file name, letting you type the change and press Enter to commit or Escape to cancel.

To use this efficiently, toggle focus to the Explorer tree by pressing Ctrl+0 (or Cmd+0 on macOS). Use your arrow keys to highlight the file you want to change, hit F2, type the new name, and press Enter. Your cursor stays right where you need it, and you can jump back into your code editor immediately by pressing Ctrl+1 (or Cmd+1).

Right-Click Context Menu

Right-clicking any file or folder in the VS Code Explorer panel opens a context menu containing the Rename command. Choosing this option highlights the filename for editing, offering an easy mouse-driven workflow if you prefer point-and-click operations over memorizing keyboard shortcuts during project reorganization.

This approach works well when you're already auditing a folder structure visually or working through unfamiliar code. The right-click menu also groups related disk operations, making it convenient to copy relative paths, duplicate files, or reveal items in your desktop OS file browser right alongside the rename action.

Automatic Import Refactoring on Rename

When you rename a JavaScript, TypeScript, or component file in VS Code, the editor can automatically update import paths across your project. Triggering this feature brings up a confirmation prompt asking if you want to rewrite references, preventing broken imports without requiring manual searching and replacing.

You can configure how VS Code handles these file movements by tweaking your global or workspace settings. Setting typescript.updateImportsOnFileMove.enabled and javascript.updateImportsOnFileMove.enabled to "always" tells the editor to rewrite relative and aliased path references silently every single time you adjust a file name, saving you from hunt-and-peck search operations across large codebases.

Refactoring Code Symbols Across Multiple Files

How to Rename Files and Symbols in VS Code (Shortcuts & Refactoring)
Photo: Art4TheGlryOfGod by Sharon (BY-ND) via Openverse

Renaming a file often requires updating matching code symbols, functions, or export statements inside your codebase. VS Code's language servers let you highlight any symbol in an open file, press F2, and change every occurrence across the entire workspace simultaneously without breaking your application build.

File renaming on disk and symbol refactoring inside code files handle two different layers of your application. Changing `UserService.ts` on disk doesn't automatically rename the `class UserService` declaration inside that file. To keep your filenames and implementation details in sync, you'll want to combine file-level renaming with AST-aware symbol refactoring.

Language extensions for TypeScript, Python, C#, and Go parse your syntax tree in real time. That means symbol refactoring knows the difference between an actual function export and a matching word inside a plain text comment or string literal, protecting you from naive search-and-replace bugs.

Symbol Renaming vs. File Renaming

File renaming changes the asset name on your operating system's disk, whereas symbol renaming modifies variable, class, or function identifiers inside source code. While file renames update module import paths, symbol renames update internal references where those export definitions are actually consumed by your scripts.

For example, if you have a React component named Header.tsx containing export const Header = () => ..., changing the file name to Navbar.tsx updates the import statements in other files to point to the new filename. However, the component function itself remains named Header until you execute a symbol rename on the identifier itself using F2 inside the editor window.

Finding All References Before Refactoring

Pressing Shift + Alt + F12 or selecting Find All References from the code editor menu displays every location where a symbol or file module is imported. Checking this reference list beforehand prevents accidental code breaks when modifying widely used utility functions or global shared layout files.

The References panel groups matches by file and displays code previews for every hit across your workspace. Scanning this tree gives you a quick sanity check before committing a major refactor, helping you verify that dynamic calls or configuration files won't get caught off guard by structural changes.

Best Practices for File Naming Conventions

Adopting clear file naming conventions makes project structures predictable and reduces friction across development teams. Standardizing on consistent casing like camelCase or kebab-case, using self-explanatory filenames, and avoiding OS-restricted special characters prevents cross-platform build errors while keeping your directory tree easy to navigate at a glance.

Inconsistent naming schemes make codebases frustrating to navigate. When one developer creates `user_controller.js`, another creates `UserController.js`, and a third writes `user-controller.js`, finding files via fuzzy match (`Ctrl+P` / `Cmd+P`) becomes a guessing game. Pick a convention early and enforce it through linter rules and team documentation.

Operating System Case Sensitivity and Git

Operating systems handle case sensitivity differently: macOS and Windows defaults treat File.js and file.js as identical, while Linux treats them as separate files. Standardizing on kebab-case or lowercase prevents tricky Git tracking bugs where casing changes fail to register properly during team collaboration.

If you rename `myComponent.js` to `MyComponent.js` on Windows or macOS, Git often fails to detect the case change because the underlying filesystem considers both names identical. When that code lands on a case-sensitive Linux CI/CD build runner, the build fails outright. Running `git mv myComponent.js MyComponent.js` directly in the integrated terminal forces Git to record the exact case shift across all environments.

Choosing Descriptive Names

Descriptive filenames explain a file's purpose immediately without requiring developers to open and read the source code. Replacing ambiguous names like helper.js or temp.py with explicit labels like userAuthentication.ts keeps projects maintainable as codebases expand over time across multiple sprints and authors.

Aim for balance between clarity and brevity. Extremely deep nested paths combined with verbose names—such as /src/services/user/authentication/helpers/userAuthenticationHelperService.ts—create visual noise in tabs and tree views. Keep your directory hierarchy reasonably flat and let clear, distinct file names communicate responsibility.

Customizing the VS Code

FAQ

How do I rename a file in VS Code?

Right-click the file in the Explorer view and select "Rename." Alternatively, select the file and press F2 to rename it in place. VS Code will automatically update references.

Can I rename a file using keyboard shortcuts?

Yes! Select the file in the Explorer, then press F2. A text box will appear, allowing you to type the new name and press Enter to save the change.

What characters should I avoid in VS Code filenames?

Avoid characters like `\ / : * ? " < > |`. These are invalid characters in many file systems and can cause issues with VS Code and other programs.

🛍 See today's best prices on Amazon and grab the option that fits you.

Editorial Team Author & reviewer

Hands-on reviewers testing tools, apps and services so you do not have to. Every article here is hands-on tested and human-reviewed before publishing.