Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does anyone know a visual studio keyboard short cut to swap around two sides of a statement?

Just wondering if anyone knows the keyboard shortcut to swap around two sides of a statement. For example:

I want to swap

firstNameTextbox.Text = myData.FirstName;

to

myData.FirstName = firstNameTextbox.Text;  

Does anyone know the shortcut, if there is one? Obviously I would type them out, but there is a lot of statements I need to swap, and I think a shortcut like that would be useful!

Feel free to throw in any shortcuts you think are cool!

My contribution would be CTRL + E, D - this will format your code to Visual Studio standards! Pretty well known I'm guessing but I use it all the time! :)

UPDATE

Just to let everyone know, using a bit of snooping of the article that was posted, I managed to construct a regular expression, so here it is:

Find:

{.+\.Text = myData\..+};

And replace with:

\2 = \1;

Hopefully people can apply this to their own expressions they want to swap!

like image 334
New Start Avatar asked Sep 21 '10 11:09

New Start


4 Answers

I think the following thread is a good place to begin with

Invert assignment direction in Visual Studio

like image 174
drhanlau Avatar answered Oct 01 '22 05:10

drhanlau


Here's how I would go about doing that without a specific keyboard shortcut:

  • First, select the text you want to modify and replace

    " = " with "                 =               "
    

    (the key here is to add a lot of spaces).

  • If you hold down Alt and use the mouse, you can select a "block" of code. Use this to select only the text on the right side of the equation (it's helpful to add extra white space here in your selection)
  • Use the same Alt + Left-Click combination to select the beginning of the left side (just select a blank area). You should be able to paste text into here.
  • If you added extra white space to the text you just added, just should be able to easily insert an = using the Alt + Click technique. Use the same trick to remove the equal sign that's dangling on the right side of your code block.

While this might not do exactly what you're looking for, I've found these tricks quite useful.

like image 35
Ben McCormack Avatar answered Oct 01 '22 03:10

Ben McCormack


If you're using ReSharper, you can do this by pressing CtrlAltShift + or

like image 27
Igal Tabachnik Avatar answered Oct 01 '22 04:10

Igal Tabachnik


The feature is in Resharper. Select the code segment and click the content wizard, which is a pencil icon in the left corner reading View Actions List, then choose Reverse Assignment. It is done.

like image 31
Boveyking Avatar answered Oct 01 '22 03:10

Boveyking