Click here to Skip to main content
15,867,764 members
Articles / Programming Languages / Javascript
Alternative
Tip/Trick

Visual Studio Box Selection with Alt Key

Rate me:
Please Sign up or sign in to vote.
4.92/5 (11 votes)
24 Jun 2023CPOL1 min read 13.8K   7   1
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:

SQL
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:

SQL
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Russian Federation Russian Federation
"It is best to erase all personal history, because that would make us free from the encumbering thoughts of other people."

Journey to Ixtlan by Carlos Castaneda

Comments and Discussions

 
PraiseNice! Pin
Ravi Bhavnani17-Jul-17 7:35
professionalRavi Bhavnani17-Jul-17 7:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.