Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Working with rectangular blocks of code in Visual Studio

📅 2012-Jun-07 ⬩ ✍️ Ashwin Nanjappa ⬩ 📚 Archive

[caption id="attachment_2581" align="aligncenter" width="499"][ ](https://codeyarns.files.wordpress.com/2012/06/20120607-block.png) Select, delete and insert with a rectangular block of code.[/caption]

Working with rectangular blocks of code is easy in Visual Studio 2010 and later. The Alt key is the key (sic) to work with rectangular blocks of code.

To select a rectangular block of code using keyboard, keep Alt pressed along with Shift and arrow keys to select code. To select a rectangular block of code using the mouse, keep the Alt key pressed when you select with left button of mouse.

Once a rectangular block of code is selected, it can be deleted by pressing Delete or Backspace.

You will notice that a vertical line remains in its place. If you start typing some text here, that text will be added at every line in the block. This trick can be used to add a prefix to many lines of code. That is, while keeping Alt and Shift pressed, use Down arrow key to select the lines where you want to insert. A blue vertical lines appears on these lines. Type any characters and they will be added to every selected line.

Tried with: Visual Studio 2010