FAQ: Rectangular selection in Visual Studio
Q: I need to delete some code from several lines and the code is well formatted. Can I use some sort of regular expression to replace the code?
A: You could but this might be overkill. VS has supported rectangular selection for a while. With rectangular selection you can select a block of code and then select that same block on several consecutive lines and then delete the selected code.
Do the following to use rectangular selection.
- Place the caret on the column where you want to begin selection.
- Hold down the ALT key.
- Drag the mouse to select the region you want to select. If you cross lines then the same columns are selected on all the lines.
- Release the ALT key and then press DEL to delete the columns from each line.
Starting with VS2010 some new capabilites were added. They are discussed here. My personal favorite is the ability to replace the same block of code on all lines (such as renaming private to public).
To do that just select the region that you want to replace and then begin typing the replacement text.