DEV Community

Cover image for Productivity with Visual Studio: Navigation | Part 2
Fernando Sonego
Fernando Sonego

Posted on • Edited on

Productivity with Visual Studio: Navigation | Part 2

In the previous post, we saw how to increase our productivity by maximizing the use of Visual Studio. Now it's up to the topic of Navigation tricks in the tool. All these functionalities that we will see will help us move more quickly within the code and go to the exact points that we want in our project or solution.

Home

The first thing we learn to use is the command ctrl + shift + f, but we have much more. Fortunately, the tool offers us many functionalities to achieve better navigation in the code.

Search bar

Above the title bar, we have a search bar available. Very few people see that it is there. If you work with Visual Studio Code you surely know this functionality, they are very similar in Visual Studio. This allows us to search through various objects such as Code elements, files, Visual Studio command, Settings, and much more!

we can see in the image, we write, for example, IApp Visual Studio will search for everything related to interfaces, configurations, files, etc. As we continue to write, the search listing will change. Just clicking on an item in the list will take us to the desired place.

If we write command, such as Go To Line, it not only shows us the shortcut but also, if we click on it, it activates the command showing us the dialog window to select the line we want to go to.

Search bar

These search tools are very powerful, but we have even more in the next section.

Elements in the code

When we must search for elements in our code the best way is to use the combination ctrl + t. The difference with the previous one is that instead of searching the entire Visual Studio, it will allow us to search for elements related to the code: Lines, Files, Types, members, and Symbols.

Elements in the code

If we write for example IApplication again, it will search all our code elements, you can see in the image even in a test project. If we wanted to search only the interfaces or the related type we can add the filter t using it this way t IApplication. We can learn each of the filters to do a faster search. To further refine the search, we can use ctrl + alt + c limiting the search to the current document, or alt + x, for the rest.

Elements in the code

Something interesting we can do is customize it. At the top right, we can see a gear, selecting it will give us 3 options, use in a tab preview, show the details and center the result on the screen. We can adjust it to our comfort.

Elements in the code

Go to the definition or see it in the same editor

Something we commonly do is go to the definition of a class or interface to see what it has implemented. We do this with the F12 key. This key takes us directly to the definition by opening the file involved, but sometimes, it is tedious having to change tabs to get back to where we were working. For this, we have the following improvement using alt + f12. This will open a small window, within the editor, that will let us see the implementation code without changing places or opening a new tab.

Go to the definition or see it in the same editor

If we want to see all the available navigation options, we can right-click on our code and the context menu will open. Note all the options that we have available:

Go to the definition or see it in the same editor

Search References

To quickly see the references on an element or object we must position ourselves on it and press shift + f12. This will open the references window:

Search References

To quickly see the references on an element or object we must position ourselves on it and press shift + f12. This will open the references window:

Search References

Also, we can group the results by projects, types, by files and some more.

Move lines up or down

CodeLens

This is one of the features that I like, when it came out it was not to the liking of many people, but over time, it became so useful that everyone loves them today. Above identifiers, we can see the word reference with the number of references that the identifier has. With Git we can see the last modification and commits if we select it.

CodeLens

As we can see in the image, when clicking on references, the list will open and we will be able to choose an item that will take us to the corresponding code.

Go to Base or implementation

When positioning on an identifier we can do 2 things, first pressing alt + home will take us to the base class or the implementation interface. But, if we press ctrl + f12 it will take us to the derived classes or classes that implement an interface.

Go to Base or implementation

Call hierarchy

The call hierarchy allows us to navigate through all the invocations from a method, property, or constructor, allowing us to examine various levels of code and to see the complex paths of one or several calls.

To use it we must stop on a member, we will press ctrl + k ctrl + t, the window will open where we can see the hierarchy of calls.

Call hierarchy

Find Comments: TODO

According to Clean Code practices, the only comment allowed is TODO. TODO allows us to leave a comment for something we should do later. We can track these comments from the Task List window that Visual Studio has.

Find Comments: TODO

We can define a query if we want, we can do this from, Option > Environment > Task List:

Find Comments: TODO

Lines of code

In the previous post, we saw that we can put marks in our code, this is something similar to those marks. We can put direct access to a line of code with the ctrl + k + h keys and with the same combination, we deactivate it.

Once we place a mark we can visualize them in the Task List. Something interesting is that if we close Visual Studio, they will remain the next time we resume work.

Lines of code

Go to closings and select by block

We can stop on a { and go to the corresponding closing } by pressing the corresponding key ctrl }. If we are standing on }, pressing ctrl {, it will go to the start. This can also be done with () [] and <>.

Also, if we press Ctrl + Shift }, it will select the block.

Go to closings and select by block

Conclusions

I hope they are useful and help you increase your productivity. Remember, with a little practice, you will be able to remember and master them without problems. In future posts, we will see other functionalities that allow us to be more productive with this wonderful tool called Visual Studio.

Top comments (0)