Codementor Events

Getting around your code in Visual Studio

Published May 07, 2023
Getting around your code in Visual Studio

Cross-posted from my personal blog.

Browsing through the folder via the Solution Explorer is OK for small solutions, but once it grows, it can get pretty sluggish. That’s why getting around your code fast is crucial to be effective. Thankfully, Visual Studio has been around for some years, so they’ve got us covered.

This Go To feature allows us to jump directly to any file. The default shortcut for it is Ctrl+T, and it will open a window that you can use to search for your file. But you can do even more: you can jump directly to a method or even a variable. It’s so flexible that it’s hard to not land where you want to. You can also use the buttons in the toolbar if you’re going to filter your results.

I seriously recommend you get used to this shortcut. Really. My life as a developer got so much easier after it. Still hard, but way easier.

This is another great Go To feature which allows us to jump directly to a line. It’s not as powerful as the previous one, but sometimes it’s enough. For example, if we’re checking the comments in our pull request, we can just check the line where the comment was made and hop to it.

When going through a method, it’s pretty normal to have to check what it does exactly, especially if doesn’t follow good practices regarding naming. To facilitate this chore, Visual Studio provides us with 2 shortcuts: Go to declaration (Ctrl+F12) and Go to definition (F12).

Go to definition allows us to go directly to the method’s body, provided it is in the same or another class. Thing is, it won’t work for interfaces, because the method can be in more than one place, right? That’s where Go to declaration shines, it allows us to choose a class to open.

So, after jumping to a method definition, it might take you to some deep corners of your code, or, even worse, not even your code. And even worse, you have 20+ tabs opened. How do we get back to where we were before? If we are not able to do it easily, we might lose our thought process, which is a huge bummer.

The solution is pretty easy: Ctrl + – (that’s a minus). It’s the navigate backward command, which takes us back to where our cursor was before. And obviously, we also have the option to navigate forward, Ctrl + Shift + -. You can find them both in the upper left corner.

I don’t personally use them, but I really think I should. Placing bookmarks around can make jumping through a frequently used piece of code very easy. You can sow them through your code and then just hop from one to another using Ctrl + B, P/N. It’s especially helpful when you are threading through unknown territory and want to avoid getting lost.

Those are the shortcuts I use the most when getting around my code, and they truly save me lots of time and also help me avoid frustration. It can be pretty upsetting having to shuffle often through your tabs to find what you are looking for. In case you have some to contribute, feel free to share them in the comments!

Discover and read more posts from Henrique Dalcin Dalmas
get started