Box Selection : Dynamic Selection In Visual Studio Editor
Usually software provides loads of functionality out of which only a small percentage is used, and if the software is from Microsoft then its not possible to be aware of all the functionality. One such functionality that Microsoft's Visual Studio provides is Box Selection. This feature was introduced in Visual Studio 10 version. Lets learn more about this feature.
In this next example we have a c# code snippet in which there are multiple variables declared. Now suppose I want to change the type of the variables from int to float. Now in part 2 I have manually changed the first int to float. Also copied the float text. Now in part 3 I have box selected the remaining int texts. After selection I just pasted the copied float value using Ctrl+V and got part 4 as an outcome.
Here's another example. Suppose you want to change the name of the variables. Instead of variable1, you want to change it to differentVariable1. So in part 1 you can select the starting letter v of all the variables and replace v with differentV in the selected text. So you will get part 3 as an outcome.
What Is Box Selection?
Box selection is a feature of Visual Studio Editor by which we can select lines of text/code dynamically in the shape of desired rectangle area. As shown in below image a user can select a desired rectangular area out of the multiple lines and only the text beneath that area will be selected.
The below image shows the difference between a normal selection and box selection.
How To Use Box Selection?
There are two ways of doing it. One by using mouse and another by using keyboard.
- For selection by mouse: While a normal selection is done by clicking left mouse button and dragging over the text, box selection is done by pressing ALT key together with left mouse button and dragging.
- For selection by keyboard: All you have to do is press ALT & SHIFT keys together with arrow keys to select whatever area you want to select.
What Is The Need For It?
Box Selection becomes very helpful when we require to change or replace certain text only in a specific region. Let me show you some examples where you can utilize this feature and thanks Microsoft for saving your precious time.
In below example we have a ul tag inside which we have list of text but now we want to create li tags out of these texts. So in part 1 we have box selected the front part and started typing '<li>'. So as an outcome we got the result in part 2. Now in part 3 we have selected the end part to create closing tag of li.
As you can notice the box is not there, only a single line is there which is a box selection of zero width. Now we type '</li>' to close the tags and as an outcome we get part 4.
Entering Text Using Box Selection |
In this next example we have a c# code snippet in which there are multiple variables declared. Now suppose I want to change the type of the variables from int to float. Now in part 2 I have manually changed the first int to float. Also copied the float text. Now in part 3 I have box selected the remaining int texts. After selection I just pasted the copied float value using Ctrl+V and got part 4 as an outcome.
Here's another example. Suppose you want to change the name of the variables. Instead of variable1, you want to change it to differentVariable1. So in part 1 you can select the starting letter v of all the variables and replace v with differentV in the selected text. So you will get part 3 as an outcome.
You can also box select a certain area and copy the specific text and paste it somewhere else. Only the text under the box would be copied. You can try it yourself. There are many ways in which this Box Selection feature can be useful to you.
If you use Notepad++ then you will be glad to know that it also supports Box Selection feature.
So that's it from our side. Try using this in your daily coding and you will realize how helpful it is. Do let us know for any more queries we would be happy to help.
Interested in video tutorial? We have one for you on this
Happy Learning!!!
Very useful information...keep posting...
ReplyDelete