Box Selection and Multi-Line Editing with VS 2010

This is the twenty-second in a series of blog posts I’m doing on the VS 2010 and .NET 4 release.

I’ve already covered some of the code editor improvements in the VS 2010 release.  In particular, I’ve blogged about the Code Intellisense Improvements, new Code Searching and Navigating Features, HTML, ASP.NET and JavaScript Snippet Support, and improved JavaScript Intellisense.  Today’s blog post covers a small, but nice, editor improvement with VS 2010 – the ability to use “Box Selection” when performing multi-line editing.  This can eliminate keystrokes and enables some slick editing scenarios.

[In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]

Box Selection

Box selection is a feature that has been in Visual Studio for awhile (although not many people knew about it).  It allows you to select a rectangular region of text within the code editor by holding down the Alt key while selecting the text region with the mouse.  With VS 2008 you could then copy or delete the selected text.

VS 2010 now enables several more capabilities with box selection including:

  • Text Insertion: Typing with box selection now allows you to insert new text into every selected line
  • Paste/Replace: You can now paste the contents of one box selection into another and have the content flow correctly
  • Zero-Length Boxes: You can now make a vertical selection zero characters wide to create a multi-line insert point for new or copied text

These capabilities can be very useful in a variety of scenarios.  Some example scenarios: change access modifiers (private->public), adding comments to multiple lines, setting fields, or grouping multiple statements together.

Great 3 Minute Box-Selection Video Demo

Brittany Behrens from the Visual Studio Editor Team has an excellent 3 minute video that shows off a few cool VS 2010 multi-line code editing scenarios with box selection (note: enable your speakers as there is audio during the demo):

 

Watch it to learn a few ways you can use this new box selection capability to optimize your typing in VS 2010 even further:

Hope this helps,

Scott

P.S. You can learn more about the VS Editor by following the Visual Studio Team Blog or by following @VSEditor on Twitter.

23 Comments

  • LOVE the box selection improvements! Can't imagine a time when we lived without these :)

  • Very handy feature...Thanks ;-)

  • This feature is particularly useful when restructuring HTML as it often includes many repetitive blocks that line up in the editor vertically. E.g. changing



    Link 1
    Link 2
    Link 3



    to


    Link 1
    Link 2
    Link 3

  • Nice, cute and useful feature. Thanks =)

  • You can also move/copy a box selection by dragging/ctrl dragging your cursor.

    Raj

  • This is a bit of a non feature. While it "looks" cool, its not really needed and you can pretty much get the same thing with find/replace in selection ( and we have had box selection for ages). In fact you are way better of becoming a find/replace ninja. It would of been nicer if there was awesome improvements to find/replace to make it find/transform. which is what people generally want.

    prime example being in the Video shown, she pasted all the pens with ;, and then had to manually edit them out. A Semantic paste would omit the ';'! There's all kinds of cool things like this that could be done...

    but no.... Microsoft and the visual studio team are going WOO HOO! look at this cool feature we have just added that many other editors have had for years WOO HOO, look look! how embarassing.....

    Tell us when you actually have something cool to look at in the editor!

    ( Because there are heaps of other cool stuff in Visual Studio 2010, but the editor and a number of the standard dialogs still suck and haven't really changed much... look at the keybinding window for instance. But woo hoo, I can zoom my font in and out, woo hoo, just what I didn't need. Sure maybe I'll use it giving a demo.... but would of traded that in a heart beat for a billion other improvements)

    *sigh* ok, I'll stop bleating. But hey, maybe Microsoft can use all their smarts to make code editing amazing? that would be cool.

  • This is a great feature, but I think multiple line edit on different column positions (not on a straight vertecally line) is needed to make it truly useful. But great with more of these simple but delicious editor features!

  • I'm sorry UltraEdit, this was why I kept you around... :~(

  • Finaly VS caught up with VI. This was introduced in VIM about 15 years ago.

  • Very nice and handy. Thanks

  • Good video & useful information , thanks :)

  • This is a nice feature. I've been using box editing in VS for many years and it's cool to see it not only preserved in the new editor, but extended in a useful way.

    Keith, want some cheese?

  • @Leonid Volnitsky: Next thing you know, VS will copy VI even more and you will be able to close the files with the all-time-favourite command: "Escape-colon-q" - ESC:q

  • Scott, thanks for posting this video. I think there should be more and more feature videos in this format. It's concise, straight to the point and Brittany Behrens's voice is very sweet and gentle. I'm looking forward to more great videos like this.

  • In Notepad++ it is possible to move the current line up and down with CTRL+ALT+UP/Down.
    Is something like this possible in VS 2010?


  • Hi thanks for the great post,

    I have question related to Silverlight control inheritance, it can be solved by many simple ways, one of them is to prevent the designer custom tool "MSBuild:MarkupCompilePass1", from specifying in the designer generated partial class, the inheritance to User control...

    public partial class MyControl : System.Windows.Controls.UserControl {

    ...
    }


    That way in the control code class we simply set the parent of the control, without having different parent classes,
    each time the designer generates it code..

    Regards

  • Box selection has always been a cool feature that came in real handy when you're block copying and editing lines of code (like converting #define lines into enums). The new ability to change all the lines to the same thing is going to make this process even easier. Great addition.

  • this looks good, but i wonder if its possible to do it with refactoring as well?
    not much advantage gained if you can easily modify groups of variables, but then have to go through all your code anyway.

  • Cool feature. Can be useful in repetitive chunks of code.

  • This is very cool and useful feature.

  • Very nice.

    Just spotted that it doesn't give smart tag for updating references to renamed objects once she changed prefix for those fields.

    --- Milan

  • Box editing is good, but the Brief editor key mapping was betting. Rather than ditch the Brief keyboard, MS should include allow these keyboard mappings to be included in the standard mapping, rather than replacing the standard key mapping, and allow everyone to see how quick they are to use.

  • Scott, an important enhancement to box selection that was introduced in VS2010 that I seldom see mentioned is that it now supports selection via the keyboard. For me I prefer the keyboard for most actions especially selection, now in VS2010 Shift+Alt+[Up,Down,Left,Right] will create a box selection. This is especially nice for the zero width insertion point selection.

Comments have been disabled for this content.