Rename a code symbol refactoring
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
This refactoring applies to:
What: Lets you rename identifiers for code symbols, such as fields, local variables, methods, namespaces, properties and types.
When: You want to safely rename something without having to find all instances, and copy/paste the new name.
Why: Copy and pasting the new name across an entire project would likely result in errors. This refactoring tool will accurately perform the renaming action.
Highlight or place the text cursor inside the item to be renamed:
Next, use your keyboard or mouse as follows:
- Press Ctrl+R, then Ctrl+R. (Note that your keyboard shortcut may be different based on which profile you've selected.)
- Select Edit > Refactor > Rename.
- Right-click the code and select Rename.
Rename the item simply by typing the new name.
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 appears at the top right of your editor.
When you're happy with the change, choose the Apply button or press Enter and the changes will be 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 is not supported for partial types with multiple definitions.
If you use a name that already exists which would cause a conflict, the Rename box will warn 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>.
Submit and view feedback for