This blog has, IMO, some great resources. Unfortunately, some of those resources are becoming less relevant. I'm still blogging, learning tech and helping others...please find me at my new home on

Wednesday, October 28, 2009

Badass Box Selection

Brittany Behrens on Monday re-introduced the much-improved version of Box Selection that came out with the Visual Studio 2010 Beta 2 bits.  I was stoked about this earlier in the year.

I’m continually surprised when I see how many of my friends aren’t aware of so many of the time-saving tools that exist inside Visual Studio.  It feels more and more like you can “run” when you code and less and less like you have to push through it.

I found a neat little compound trick using a couple of the features that I routinely exploit.  Starting from essentially the same place as Brittany, I copied and pasted a list of variables into some multiline Console.WriteLine statements.  That was pretty cool.  Like Brittany, I was left with a series of semi-colons that I wanted to remove. 

To get rid of the punctuation, I simply redo the box selection and then invoke the Find and Replace dialog with Ctrl-H:


From there, I can employ a simple matching technique and scrub the semi-colons.  Just make sure you have Look in: Selection selected and hit Replace All.

If it were a more complex scenario, I could have also used regular expressions in Find and Replace (located in “Find Options”) to be more discerning on the text I was replacing. 

I Like Pushing Arrows

There is something else in here of a hidden gem that wasn’t fully revealed in the video but that I picked up on (I heard Brittany tapping on the keyboard and had to try it out): using the cursor keys while holding down Shift allows you to “walk the box” and change the shape of the selection.

After using Alt+Mouse or Shift+Alt+Arrows to box-select, use Shift+Arrows to alter the target of the selection. 

Let me Choose!

One thing that I liked in the video was that the white space was copied as well.  This left the pasted text block-aligned and ready to go.  The video obviously pre-dates the version of box selection in Beta 2, however, because as you can see from my above image, there is no whitespace after my variable names (watch the video to see the difference).

I think it would be good to have some optional, intermediary dialog box that you could call up (perhaps a la Office-Ctrl tapping) that would allow you to preserve or remove whitespace, punctuation, etc. 

I suspect that the visibility of the selection is made available to any plug-ins, but I also hope there is something by way of box selection events so that context menus can leverage this.  Not having worked with the extensibility bits around selection in the editor, I’m not sure if you can distinguish between box selection and stream selection when creating something to extend the IDE.

No comments:

Post a Comment