Visual Studio Box Selection with Alt Key


This tip is just a reminder on the Box Selection — a cool feature which 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 being 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.

The similiar selection result can be achieved with a keyboard:

  • place a text cursor on a start position in your text,
  • press and hold the Alt key together with the Shift key,
  • operate the keyboard arrow Right, Down, Up, Left 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 null,
 Surname nvarchar(50) not null null,
 Forename nvarchar(50) not null null,
 Gender bit null,
 Birthday date null 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.