VisualStudio: shortcut for renaming variables

In Visual Studio, when you rename a variable name in its definition, there is a slight underscore in the last letter, so if you hover over it, you will get the option “Rename OldVaribleName to NewVariableName” and thus rename all entries in this procedure to this variable.

Is there a shortcut for this and not use a mouse?

+57
visual-studio keyboard-shortcuts
Jul 08 '09 at 15:05
source share
12 answers

They are known as smart tags.

You can use CTRL + .

Shift + Alt + F10 is another option.

+70
Jul 08 '09 at 15:08
source share

As an updated answer ...

Update for Visual Studio 2017

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

Visual studio 2015

In Visual Studio 2015, if you click on a variable and use Ctrl + R, Ctrl + R , it will lock the variable name and select all instances of the variable. Then, when you start to enter a new variable name, it will rename all instances at once. Press "Enter" to exit when you are done (note: differences may exist between versions of updates. See Comments below).

Edit: one warning on this approach. If you use Razor in your views, it will not necessarily rename these variables. I did not make an empirical experiment to see if there are certain cases when he makes or does not select them, but I definitely had a few cases when he renamed more strongly typed variables in server code (DAL and controllers), but not views.

+30
Jun 24 '16 at 20:53 on
source share

Depending on the default keyboard mapping scheme used, you may slip away by simply pressing F2 to call Rename before typing when changing text.

If your version of VS does not have a displayed F2 , you can rename it from the program Main menu:

  • ToolsOptions
  • In the Options dialog box, expand Environment , and then select Keyboard
  • Type File.Rename in the "Show Commands Containing" search field
  • Select "Press Shortcuts" TextBox and press F2
  • Click Assign

screenshot

+11
Feb 25 '15 at 19:10
source share

In VS 2008 using C # you can just press F2 , but you are not sure about other versions / languages. It also renames files in Windows Explorer if you are too lazy to right-click like me.

+6
Jul 08 '09 at 15:29
source share

I think the default is Ctrl + . .

+5
Jul 08 '09 at 15:09
source share

Ctrl + h work for me. Good luck.

+5
Sep 20 '15 at 15:27
source share

If you like it, I suggest you try ReSharper , it provides many features to refactor your code.

In ReSharper, to rename a variable or function, simply use the shortcut CTRL + R , R.

(I know this may not be the answer to your question, but I think if you like to use keyboard shortcuts that you like ReSharper).

+4
Jul 08 '09 at 15:13
source share

In Visual Studio 2013, the shortcuts listed are Ctrl + . , F2 , etc. don't work for me.

I found that installing Visual C ++ Refactoring expanded my problem.

Now I can use Ctrl + R , which brings up the refactoring popup and allows me to select the current default area, as well as other instances in the same file.

PopUp Refactoring

Here is an example of a variable that I renamed to a function. There was another function with the same variable name, which is proposed to be renamed ...

Refactoring Menu

+3
Sep 10 '15 at 8:31
source share

Quick notes: Ctrl + . works. But if you do not press backspace, then rename the variable name.

eg. rename S enderEmail to s enderEmail

If you highlight S in S enderEmail and replace the letter, then use Ctrl + . , you will see a popup to rename the variable. If you add a letter to the variable, this still works. If you delete, it still works.

However, this is what I do a lot - if you press backspace on S enderEmail and make it enderEmail, then add s , making it s enderEmail, and then press Ctrl +. it will not work.

Shift + Alt + F10 also works in the same way.

Hope this helps! :)

0
Jul 05 '16 at 19:29
source share

After renaming: CTRL + .

Before renaming: CTRL + r , r

VS 2017, smart tags included

0
Dec 11 '18 at 9:15
source share

I was looking for this in 2019 ... What helped me was to go to Options and add a shortcut for the Refactor.Rename command, for example this

0
Aug 08 '19 at 9:49
source share

I am using ctrl + f

It opens a window that you can use to search and replace all occurrences of a word. You can replace the word in “Current Document”, “All Open Documents”, “Current Project” or “Whole Solution” in the drop-down menu under the “Replace All” button when you hover over it.

I hope this helps.

enter image description here

-2
May 20 '15 at 17:24
source share



All Articles