Blog for Junior Developers C#/.NET

Thursday, June 27, 2024

I often read posts on various internet forums from younger programmers on how to make working with their IDE, in this case Visual Studio, easier, so that programming can be faster and more enjoyable. The first thing that comes to my mind is, of course, using keyboard shortcuts. In Visual Studio, we can assign our keyboard shortcuts to various functions, but in this article I would like to share with you only the shortcuts that are default in Visual Studio and those that I often use and recommend. You don't have to learn them by heart, over time, if you try to use them, they will all become familiar to you. I recommend starting with a few and if they become a habit, you can add new ones. I will also add that the shortcuts I present are the default ones after installation in Visual Studio, without using resharper.

40-visual-studio-keyboard-shortcuts-every-programmer-should-know.jpg
40 Visual Studio Keyboard Shortcuts Every Programmer Should Know:


#1 [Ctrl]+[Shift]+[B]
First, build and launch the application. With this shortcut you will build the entire solution without launching the application.

#2 [Ctrl]+[F5]
The next shortcut will run your application without a debugger.

#3 [F5]
Starting application debugging, i.e. running the application with the debugger.

#4 [Shift]+[F5]
Stop debugging. If you have previously launched the application with a debugger, you can use this shortcut to stop the entire application.

#5 [F9]
Inserting and deleting breakpoints. Just hover your cursor over a specific line and click [F9].

#6 [F10]
If you have run the application in debug mode, you can use this shortcut to go one step forward - it is a transition to the result of the executed method, without going inside it.

#7 [F11]
However, if you want to get inside a specific method, first use this shortcut in the appropriate place in debug mode.

#8 [Shift]+[F11]
Thanks to this shortcut, you can take a step back while debugging and, for example, exit from inside the method.

#9 [Ctrl]+[Shift]+[F9]
With one shortcut you can remove all previously added breakpoints.

#10 [Ctrl]+[.]
If you do not use resharper, this will be the most important shortcut for you, thanks to which, when you place the cursor in the right place, you will see suggestions.

#11 [Ctrl]+[Shift]+[Space]
You place the cursor at the parameters where you call the method, then hints about the parameters of this method are displayed.

#12 [Ctrl]+[Space]
Sometimes in VS it happens that IntelliSense suggestions are not displayed, with this shortcut you can force these suggestions.

#13 [Ctrl]+[M]+[M]
You may want to use a shortcut to hide the body of a method that you don't need at the moment and, for example, interferes with the readability of another piece of code. Using the same shortcut, you can expand the previously hidden method body.

#14 [Ctrl+F]
The next 3 shortcuts that I often use to search for phrases following my walkthrough. Use this shortcut to search an entire walkthrough, project or document by a specific phrase.

#15 [Ctrl+Shift+F]
Displays a slightly more advanced file search window.

#16 [Ctrl]+[,]
This shortcut allows you to search for specific files/classes by name. If you don't have resharper, this shortcut is very useful and you will use it often.

#17 [F12]
When you hover over the name of the called method or class, you will go straight to the definition.

#18 [Alt]+[F12]
The operation is very similar to F12 itself, except that here you can view the definition of a class or method without opening it in a new window. Just F12 will take you to a new window.

#19 [Shift]+[F12]
When you hover over the name of a class or method and use this shortcut, all references will be displayed.

#20 [Ctrl]+[K]+[C]
A frequently used shortcut simply comments previously selected code.

#21 [Ctrl]+[K]+[U]
Uncommenting the selected code, of course, if it has been commented before :)

#22 [Ctrl]+[K]+[D]
Another code worth remembering, you can use it to improve the formatting of the code throughout the file.

#23 [Ctrl]+[K]+[F]
Improves indentation and code formatting similarly to the above, but only applies to selected lines.

#24 [Ctrl]+[R]+[G]
Removing unused namespaces. It often happens that you have several unused namespaces at the beginning of the class, thanks to this shortcut you can quickly get rid of them.

#25 [Shift]+[Alt]+[UP]/[DOWN]
Adding the same changes to several lines below each other. Just place the cursor where you want to change something, then use a keyboard shortcut to move up/down and make the same changes on all lines.

#26 [Ctrl]+[Shift]+[A]
Shortcut for creating a new file opens the window for adding a new file. The file is added to the location where you are currently located, this is usually not a problem, but as a last resort you can select the folder in solution explorer and only then use this shortcut and then you can be sure that the file will be added to the correct location.

#27 [Ctrl]+[Shift]+[S]
Save all previously modified files.

#28 [Ctrl]+[Tab]
I use this shortcut very often, thanks to it you can freely switch between open windows in Visual Studio. Additionally, if you hold [Ctrl]+[Left/Right] you can even jump to other windows such as solution explorer, team explorer, etc. This is a great shortcut, I recommend trying it out.

#29 [Alt]+[W]+[L]
Another shortcut for actions on open windows, thanks to it you can quickly close all previously open windows.

#30 [Ctrl]+[F4]
Close only the active window, not to be confused with [Alt]+[F4] :)

#31 [Ctrl]+[-]
Plain backwards, just taking a step back.

#32 [Ctrl]+[Shift]+[-]
The opposite operation to point 31. So forward, that is, if we used backward, then we can go back to the place where we were before.

#33 [Alt]+[UP]/[DOWN]
With this shortcut you can move the entire line up/down. You can also move all selected text.

#34 [Ctrl]+[UP]/[DOWN]
It works like scrolling on a mouse, i.e. scrolling the screen while maintaining the cursor position.

#35 [Ctrl]+[K]+[K]
You may also find it useful to insert/delete a bookmark that you can return to later. Sometimes you need a quick break from the code and even from the computer. At times like these, it's a good idea to leave a bookmark in your code so that when you return, you can quickly get back to where you left off.

#36 [Ctrl]+[K]+[W]
If you start using the bookmarks from point 35, you can view the bookmarks you have previously saved here. You can also use [F2] to give the tab a name.

#37 [Ctrl]+[K]+[N]
Next tab, helps you move between tabs.

#38 [Ctrl]+[K]+[P]
The previous tab, similarly to the above, is intended to facilitate switching between previously saved tabs.

#39 [Ctrl]+[K]+[L]
Delete all saved bookmarks.

#40 [Your own keyboard shortcuts]
I think that above I shared with you all the keyboard shortcuts in visual studio that I use on a daily basis. However, it is worth knowing that you can add your own keyboard shortcuts, ones that will make your work easier. You can do it easily. To add your own keyboard shortcut, click in the navigation: Tools -> Options, then select Environment -> Keyboard. Select the name of the shortcut you are interested in from the list, then add your own shortcut and save.

own-shortcut.png

Summary:
Remember, however, that keyboard shortcuts are not the most important and you can get by without them using only the mouse. However, it seems to me that it is worth learning and using at least the ones I have presented to you, they will become a habit over time. I realize that there are tons of different keyboard shortcuts in Visual Studio that didn't make my list. However, I tried to include those that in my opinion are the best and those that I use the most. In point 40 I showed you how you can add your own keyboard shortcuts, but remember not to overdo the number of keyboard shortcuts at the beginning, because it will be difficult for you to remember them all. Good luck writing code more enjoyable and faster!

Author of the article:
Kazimierz Szpin

KAZIMIERZ SZPIN
Software Developer C#/.NET, Freelancer. Specializes in ASP.NET Core, ASP.NET MVC, ASP.NET Web API, Blazor, WPF and Windows Forms.
Author of the blog CodeWithKazik.com

Previous article - 100 Interview Questions (and Answers!) for Junior Developers C#/.NET (Part 10/10)
Next article - 10 Minute Guide to C# and .NET
Comments (1)
Kazimierz Szpin
KAZIMIERZ SZPIN, czwartek, 11 lipca 2024 11:06
What do you think about this article? I'm curious about your opinion.
Dodaj komentarz

Search engine

© Copyright 2024 CodeWithKazik.com. All rights reserved. Privacy policy.
Design by Code With Kazik