Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VisualStudio: Shortcut for when Renaming Variable

In Visual Studio, when you rename a variable name in its definition, there's a little underline in the last letter so if you hover that, you'll get the option "Rename OldVaribleName to NewVariableName" and so rename all entries in that procedure of that variable.

Is there a shortcut for that and not use the mouse?

like image 654
InfoStatus Avatar asked Jul 08 '09 15:07

InfoStatus


People also ask

How do you change the name of a variable in C#?

You can right click on the variable and choose Refactor->Rename from the menu, it's the most save way to accomplish it.

How do I change multiple variable names in Vscode Mac?

If you select a variable/method and hit F2, you can edit the name and it will change every instance of that variable's name throughout the entire current working project.


2 Answers

These are known as Smart Tags.

You can use CTRL+.

Shift+Alt+F10 is another option.

like image 56
Ahmad Mageed Avatar answered Oct 18 '22 09:10

Ahmad Mageed


By way of an updated answer...

Update for Visual Studio 2022

Same behavior as 2019.

Update for Visual Studio 2019

Same behavior as 2017.

Update for Visual Studio 2017

In Visual Studio 2017 click the variable and then press Ctrl + r, r. This works without an issue (see comments below about differences in Visual Studio 2015 where the whole command had to be repeated).

Visual Studio 2015

In Visual Studio 2015, if you click on the variable and use Ctrl + r, Ctrl + r it will lock onto the variable name and highlight all instances of the variable. Then as you begin typing the new variable name it will rename all instances at once. Hit enter to escape, once you are finished (note: differences might exist between update versions. See comments below).

Edit: One warning on this approach. If you are using Razor in your views, it will not necessarily rename those variables. I haven't done an empirical experiment to see if there are certain cases where it does or does not pick those up, but I have definitely had several cases where it renamed the more strongly typed variables in the server-side code (DAL and Controllers) but not the views.

like image 21
joshmcode Avatar answered Oct 18 '22 09:10

joshmcode