I have been coding in C# on Visual Studio for almost around 8 years and I have realized using some of the keyboard short keys while writing the code is just so fast than using a mouse and going around options to click. Using shortcut keys is not just cool but also increases productivity. And one more cool fact about these is you don't have to do anything in the settings to enable it. They are there already, configured by default when you install a fresh copy of Visual Studio (any version).
Keyboard shortcuts are my favorite and there just so many I love. But I'm going to list down the 5 shortcut keys that I use the most to increase my programming speed.
1. Power of DOUBLE-TAB
If I want to write a class, a constructor, a for-loop, etc, I just type the keyword and hit TAB twice. Tada! The snippet is generated.
2. Switch-Case: Case generator
If I want to write a switch-case for all values present in a very tall enum (an enum with a huge list of entries), I just generate the switch-case template using my trick of Double-Tab, enter the enum name in the switch-on place and Click on the default keyword just once. Tada!
3. Commenting uncommenting game
Often writing code, I would like to make tweaks while testing. And this requires commenting-uncommenting the lines. So, I just use
Ctrl + K + C for commenting and Ctrl + K + U for uncommenting. It is so quick!
4. Code alignment
Often writing code, it tricks me if my code is not aligned properly at all. It is difficult to identify which part belongs to other parts of the code. So, I just do Ctrl + K + D after writing the code and it is aligned. And also, if you are generating code snippets using the double-tab method, most of the code will auto-aligned. So cool!
5. Member references and definition
If I'm working on a gigantic codebase with multiple project files in a solution and I want to see all the references of a particular member like Class, Method, Variable, or Properties, I just click on that member and do Shift + F12. That's it! The reference window will be open.
And, if I'm going through code and want to know the definition of a member like Class, Variable, or a Method, I just click on it and hit F12. It takes me to the original place where it defined.
These tricks are always so fun to use. I hope you find this article useful. If you know any cool shortcut that's cool, please let me know in comments.
Top comments (1)
Hello. First of all, thank you for this valuable information. I can't run the 2nd step generator. I double-tab then click on default or somewhere else but it never generates. what should I do? I am using the latest version of Visual Studio on a macOS device.