Tuesday, November 28, 2006

Visual Studio 2005 Select Area

Page shared this great tip with me many months ago, and I completely forgot about it until today when I needed to use it.

In Visual Studio 2005, you can select a rectangular area of text without selecting the entire lines (default multi-line select behavior). If you hold down the ALT key when you select text, you can draw a rectangle spanning multiple lines. It may not be an everyday-useful feature, but there are certainly times when it comes in handy. In my case today (and in the example in my screenshots) I wanted to move several lines of comments over.

As we all know, the default select behavior looks like this:


But I wanted to select the comments (ALT-select):


And tab them over some more (TAB the selection):


I know my screenshot example here is pretty basic, but my real-world use today was about 10 lines of aligned comments like this, and a couple of keystrokes and a wave of the mouse was much faster than individually tabbing each line. I'm sure there are several other operations you can perform on a selection like this, but the ones that come to mind are tabbing and copying. This works well for situations where you have aligned comments (like my example), formatted text, etc. in your code. Let me know if you find any other handy uses for this feature. Thanks to Page for sharing this tip!

No comments: