Visual Studio Box Selection
Visual Studio 2010 and later versions include the ability to select, copy and paste, or replace rectangular areas of text. This type of selection, known as box or column selection, is similar to the functionality provided by word processors.
Visual Studio Text Selection
Most software developers that use Visual Studio will use continuous selection for text. With this style of selection, you can simply drag the mouse to highlight a continuous stream of text. For example, if you drag downwards from the centre of one line to the centre of another, all of the text to the right of the starting point and the left of the end point is selected. If you select over multiple rows, all of the lines between the first and last are entirely selected. This style of selection can also be achieved using the keyboard by holding the Shift key whilst moving the text cursor, or caret.
The following image shows continuous selection from the "H" of Hello to the quote before the "W".
A selection mode that is used less often is box selection, also known as column selection. Introduced in Visual Studio 2010, box selection allows you to highlight a rectangular area of code. With this style of selection, you can span multiple rows without selecting entire lines of text. The image below shows an example of box selection.
To select a box, you can hold the Alt key whilst dragging the mouse. To use the keyboard, hold Alt and Shift together whilst pressing the arrow keys.
Once you have selected an area of code, you can cut or copy it to the clipboard as you would any other text. Pasting a box is somewhat different to pasting a continuous selection. When you paste a rectangle of text, the rectangle is preserved. Any text already present at the insertion position is shifted to the side to make space for the pasted content.
Overtyping a Selected Box
When using continuous selection, highlighting code and typing replaces the selected text with the newly added characters. With box selection, overtyping works differently. For the initial key press, all of the selected text is removed and the inserted character is added on every line of the selection. Subsequent key presses are added to the right, again on each line. This allows you to type the same text onto multiple lines in a single operation.
You can also remove a rectangular area by performing a box selection and pressing the Delete key. The selected information is removed and the text to the side moves across to fill the gap.
19 April 2014