Microsoft Visual Studio contains hundreds of shortcuts and tricks to accomplish some lengthy tasks more easily. However, some of these are just not all that well-known or have just been forgotten because of lack of use. No, this is not a new program, but many people are still using it – and could be using it better. Here is a list of 10 tasks that coders frequently perform while writing code – and some tips that might help you get it written more quickly.
1. Remove unnecessary using namespace statements (those that are not used), and sort them in one go.
Right click on the code behind (.cs) file -> Organize usings -> Remove and Sort
2. View the spit screen vertically
This is helpful if you have a wide screen monitor. Go to Tools -> Option -> Html Designer -> General. Select Split Views Vertically, then restart VS.
3. Automatically format ugly code
The screen shot below shows an example of ugly formatted code. To format it automatically, simply press Ctrl +k followed by Ctrl + d (Ctrl + k,d) to get well-formatted code.
4. Rename a variable in a function
Select the variable to rename, then hit Ctrl + r, Ctrl + r (ctrl + r two times). Enter the new name of
the selected variable, then hit OK.
5. Add the namespace for a class
When we use any class, it is not valid unless we add a namespace for the class. We can use a shortcut method to do so. Write the class name then press Press "Ctrl + ." (control plus dot). Then, select the required namespace from the smart tag list.
6. Surround the code with a construct
We can easily surround lines of code with some constructs. Select the lines, and then press Ctrl + k , Ctrl + s (Ctrl + k,s). It opens Surround With with a smart tag listing. Then, select the required construct from the list.
7. Switch between opened files tabs
Press Ctrl + tab to switch between different opened files in VS.
8. Run an incremental search
You can instantly search within a code file by pressing Ctrl + i , and then start typing the search term. You can see the searched word as highlighted text. To move to the next occurrence, press Ctrl + i. To exit increment search mode, press Escape.
9. Create the property writing format
Write "prop" followed by a tab (prop + tab).
10. Try catch block creator
A partial Try catch construct appears by typing "try" followed by a tab (try + tab ).
We hope you find these handy shortcuts useful. Happy coding!