When I was starting out learning how to code, I never looked at how I could improve my developing skills by getting a better understanding of the IDE I was working on. I was so hung up trying to figure out what the correct syntax was and why half of my screen was covered with red squiggly lines, that I didn’t realise I was missing a trick with a lot of Visual Studio shortcuts. The following list of shortcuts will improve your efficiency and help you with debugging and solving issues.
Note: I have included the full name of the command in each section in case your key binds are set up differently. These can be changed in Tools > Options > Environment > Keyboard.
1. Find in Files (Ctrl + Shift + F)Title for This Block
If you do not know about this one, you are missing out on an incredibly useful Visual Studio feature. This command pulls up a pop-up display that allows you to search the entire solution (or the project you are currently in) for the exact word in the search box. The tool can also make use of regular expressions as well. I find that for the most part I just have it set up to search the whole solution for a word I am looking for. The results appear as a list and show the files and file paths for the hits. Find in files really comes into its own when you are dealing with a new codebase – allowing you to sift through the whole solution to find the text you are looking for.
2. Move Lines of Code (Alt + Up / Down)
Edit.MoveSelectedLinesUp / Edit.MoveSelectedLinesDown
Move lines is an excellent way to move blocks of code in a much smoother way than using copy/paste. This is particularly useful when refactoring code as it allows you to move code around quickly within a class. When you get used to using this feature you will wonder how you were ever working without it!
3. Duplicate Line (Ctrl + D)
Duplicate line does exactly what it says on the tin. It simply takes whatever line your text cursor is on and copies it to the line below. This also pushes all code below down one line – so nothing else is affected. If you have a highlighted section of code, ctrl + d will still work and duplicate the whole block to the lines below. This one will help reduce your keystrokes and hopefully in turn improve your efficiency.
4. Delete Line (Ctrl + Shift + L)
Another very self-explanatory one. Delete Line removes the line your text cursor is on and moves all lines of code below up by one line. This can also be performed with highlighted text, working in the same way. You can cut instead of deleting code by using ctrl + L, which saves the line to the clipboard.
5. Format Document (Ctrl + K, Ctrl + D)
This one is for the developers out there that can’t stand a line of code being slightly out of place. With two simple keyboard commands, your code will go from a mess to being perfectly formatted – now you only need to worry about how clean the code itself is! This command works under the assumption that all your parenthesis, in the file, are correctly closed. If they are not this will lead to incorrect indentation of your code. But with that issue aside, this command will save you a lot of time compared to manually tidying up your code.
6. Comment Code (Ctrl + K, Ctrl + C)
Commenting code is vital in the development process of new features, as well as for debugging issues. With this command, you are able to instantly comment (or uncomment with Ctrl + K, Ctrl + U) large portions of code. This is a very nice quality of life feature, as manually commenting code spanning multiple lines requires insertion of the comment syntax at the beginning and the end of the code. Being able to avoid slow, manual commenting through this Visual Studio shortcut is much appreciated.
7. Go to Definition (F12)
Have you ever struggled to find the code relating to a certain function being called from the block of code you are looking at? Well, you will no longer have this issue with the “go to definition” command. Hit f12 when the text cursor is over the function to navigate to the class containing the implementation. This technique makes navigating large, unknown code bases much easier and will give you much more confidence with implementing code changes. If your solution makes use of dependency injection via interfaces, you will need to use “go to implementation” instead – Ctrl + F12. Go to definition takes you to the interface class when used on an injected method. In this case “go to implementation” will take you to the class containing the method logic.
8. Step Over and Step Into (F10 / F11)
Debug.StepOver / Debug.StepInto
I am sure you have all used debugging tools to hit breakpoints and navigate through code. I have found that manually clicking the step over and step into commands to be quite clunky when moving through lines. Using the keyboard commands is a much smoother approach. Also, I personally think it gives a good impression to your peers if you are able to quickly move through the code without having to click a load of buttons in the UI – however, if that is something you actually care about, I will leave for you to answer. There are more debugging Visual Studio shortcuts I have not mentioned, such as “step out” (Shift + F11). I use “step over” and “step into” the most and so didn’t want to include too many here.
9. Rename (Ctrl + R, Ctrl + R)
This one is an absolute lifesaver! It renames something and updates the name in every place it is used in the solution. As is a theme with a lot of these Visual Studio shortcuts- carry out the shortcut with the text cursor over the name you wish to change. This will highlight the word and pull up a window (as shown in the image). As you alter the highlighted text, the window will update to show you what the new name is and how many files are affected. This will make refactoring a lot simpler – turning a name change from a potentially large and error-prone task of locating all uses and individually updating, to an instant and safe process!
I hope you found these Visual Studio shortcuts as useful as I do! All the ones I have included I use on a daily basis. They have definitely made me a much more efficient developer! All these commands have been so useful to me and I am sure there are many more I have missed and am yet to discover. I would love to hear, in the comments below, which ones you use and recommend.