| title | Rename and move refactorings | ||
|---|---|---|---|
| description | Learn how to use Quick Actions and Refactorings to rename code symbols, move types to matching files, sync types and filenames, sync namespaces, and move declarations near references in Visual Studio. | ||
| ms.date | 04/03/2026 | ||
| ms.topic | reference | ||
| ms.custom | awp-ai | ||
| f1_keywords |
|
||
| author | RoseHJM | ||
| ms.author | rosemalcolm | ||
| ms.subservice | general-ide | ||
| dev_langs |
|
Visual Studio provides several refactorings for renaming and reorganizing code symbols and files. You can access these refactorings through the Quick Actions and Refactorings menu (Ctrl+.).
Applies to: C#, Visual Basic
This refactoring safely renames identifiers for code symbols, such as fields, local variables, methods, namespaces, properties, and types. All references across the project are updated automatically, avoiding errors from manual find-and-replace.
-
Highlight or place the text cursor inside the item to be renamed:
-
Next, use your keyboard or mouse as follows:
- Keyboard
- Press Ctrl+R, then Ctrl+R. (Your keyboard shortcut may be different based on which profile you selected.)
- Mouse
- Select Edit > Refactor > Rename.
- Right-click the code and select Rename.
- Keyboard
-
Rename the item simply by typing the new name.
::: moniker range=">= vs-2022"
[!TIP] You can also update comments and other strings to use this new name, as well as preview the changes before saving, using the checkboxes in the Rename box that appear when you open the drop-down menu. ::: moniker-end
-
When you're happy with the change, choose the Apply button or press Enter and the changes are committed.
-
Starting in Visual Studio 2019 version 16.3, when you rename a type that matches the name of the file it's in, a checkbox appears that enables you to rename the file at the same time. This option appears when you rename a class, interface, or enumeration. This option isn't supported for partial types with multiple definitions.
-
If you use a name that already exists which would cause a conflict, the Rename box warns you.
-
Another way to rename a symbol is to change its name in the editor. Then, with the cursor in the symbol name, press Ctrl+. or just expand the light bulb icon menu that appears and choose Rename <old name> to <new name>.
Applies to: C#, Visual Basic
This refactoring moves a type to a separate file with the same name, improving code organization and navigation when you have multiple types in one file.
-
Place the cursor inside the name of the type where it is defined. For example:
class PersonClass Person
-
Next, do one of the following:
- Press Ctrl+.
- Right-click on the type name and select Quick Actions and Refactorings
-
Select Move type to TypeName.cs from the menu, where TypeName is the name of the type you've selected.
The type is moved to a new file in the project that has the same name as the type.
Applies to: C#, Visual Basic
This refactoring renames a type to match the filename, or renames a filename to match the type it contains, keeping code organized and easy to navigate.
Note
This refactoring is not yet available for .NET Standard and .NET Core projects.
-
Highlight or place the text cursor inside the name of the type to synchronize:
-
Next, do one of the following:
- Keyboard
- Press Ctrl+. to trigger the Quick Actions and Refactorings menu and select Rename file to TypeName.cs from the Preview window popup, where TypeName is the name of the type you have selected.
- Press Ctrl+. to trigger the Quick Actions and Refactorings menu and select Rename type to Filename from the Preview window popup, where Filename is the name of the current file.
- Mouse
- Right-click the code, select the Quick Actions and Refactorings menu, and select Rename file to TypeName.cs from the Preview window popup, where TypeName is the name of the type you have selected.
- Right-click the code, select the Quick Actions and Refactorings menu, and select Rename type to Filename from the Preview window popup, where Filename is the name of the current file.
The type or file is renamed.
- Keyboard
Applies to: C#
This refactoring updates the namespace to match the folder structure when you move a file to a new folder.
-
Place your cursor in the namespace name.
-
Press Ctrl+. to trigger the Quick Actions and Refactorings menu.
-
Select Change namespace to <folder name>.
Applies to: C#, Visual Basic
This refactoring moves variable declarations closer to their usage, improving readability and narrowing variable scope.
-
Place your cursor in the variable declaration.
-
Next, do one of the following:
- Keyboard
- Press Ctrl+. to trigger the Quick Actions and Refactorings menu and select Move declaration near reference from the Preview window popup.
- Mouse
- Right-click the code, select the Quick Actions and Refactorings menu, and select Move declaration near reference from the Preview window popup.
- Keyboard
-
When you're happy with the change, press Enter or click the fix in the menu and the changes are committed.
Example:
// Before
int x;
if (condition)
{
x = 1;
Console.WriteLine(x);
}
// Move declaration near reference
// After
if (condition)
{
int x = 1;
Console.WriteLine(x);
}












