How to save time, mouse clicks and keystrokes by using keyboard-shortcuts in Visual Studio.
The following list contains my favorite keyboard-shortcuts in Visual Studio:
-
ctrl + K + C (Press Control, K and C): Comments out the selected lines of code.
-
ctrl + K + U (Press Control, K and U): Uncomments the selected commented lines of code.
-
ctrl + . (Press Control and .): Use it when you want to add a new using to add a reference for what you just wrote in your code.
-
ctrl + shift + F (Press Control, Shift, F): Use it when you want to search for a term or phrase in the whole solution
-
ctrl + , (Press Control and ,): Inline global search with auto completion from Intellisense.
-
ctrl + shift + B (Press Control, Shift, B: Re-build the complete solution.
Apart from the previous shortcuts, I find it very useful that I when start typing a keyword in Visual Studio and I press tab twice Visual Studio automatically adds a complete “template”-snippet for this keyword:
-
prop: Creates a new C# property.
-
propfull: Creates a new C# property and it’s field.
-
ctor: Creates a new constructor
You can practically create every code snippet you can imagine simple by starting typing the keyword and then press tab twice. For example:
if creates a new if clause, else creates a new else clause, for creates a new for clause, try creates a new try…catch block.
Try experimenting with these commands and remember, always press tab twice :)