65.9K
CodeProject is changing. Read more.
Home

Visual Studio Box Selection with Alt Key

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.92/5 (11 votes)

Jul 17, 2017

CPOL

1 min read

viewsIcon

14643

This is an alternative for "VS2010 Box Selection with Copy and Paste"

This tip is just a reminder about Box Selection — a cool feature that is available in Visual Studio, MS SQL Server Management Studio and... even in MS Word!

What is Box Selection?

Box Selection, or Multi-Line Editing, or Column Selection is the possibility to select a rectangular region of text with mouse or keyboard arrows. The Box Selection feature is activated by pressing the Alt key on the keyboard.

To select a rectangular region of multiline text with a mouse:

  • press the Alt key
  • place a mouse pointer on text
  • holding the Alt key, press and hold the left mouse button
  • drag the mouse pointer over the diagonal to select a rectangular region
  • release the mouse button and the Alt key

A similar selection result can be achieved with a keyboard:

  • place a text cursor in the start position in your text
  • press and hold the Alt key together with the Shift key
  • operate the keyboard arrowsRightDownUpLeft to select the required rectangle
  • release the Alt key and the Shift key

The received rectangle selection can be copied and pasted, cut, and replaced.

The Box Selection is very useful when it is necessary to work with table columns and object fields. For example, it is convenient to build a select statement just by copying the fields from a create table statement.

Even more! The habit of working with columns of text, cutting and pasting text with rectangular regions, will change the style of code writing.

For example, the following create table statement is not convenient for the Box Selection:

create table dbo.People
(
    Id int not null identity,
    Nickname nvarchar(50) not null,
    Surname nvarchar(50) not null,
    Forename nvarchar(50) not null,
    Gender bit null,
    Birthday date null,
    Phone varchar(20) not null,
    Email varchar(50) not null,
    Notes nvarchar(500) null
);

but this one is:

create table dbo.People
(
    Id          int             not null    identity,
    Nickname    nvarchar(50)    not null    ,
    Surname     nvarchar(50)    not null    ,
    Forename    nvarchar(50)    not null    ,
    Gender      bit                 null    ,
    Birthday    date                null    ,    
    Phone       varchar(20)     not null    ,
    Email       varchar(50)     not null    ,
    Notes       nvarchar(500)       null
);

And this Box-Selection-Ready or Alt-Style code is more readable and less error-risky than the first statement.

Show Me How!

Here is the animated example of the Box Selection in action:

Box Selection

The above GIF animation has been created with ScreenToGif program.