Visual Studio — Tips to Increase Productivity

Henrique Siebert Domareski
17 min readApr 2, 2024

Visual Studio offers several features and shortcuts that provide a better coding experience. In this article, I present some tips that will increase your productivity when using Visual Studio.

I’ve been working with Visual Studio for more than 10 years, and during these years I learned some useful shortcuts and features that help me in my working day. Below you will find an enumerated list of all the features/shortcuts presented in this article. Many of them I use daily, and others not so frequently. May these tips serve you well.

1. Search a file by name
2. Minimize and Maximize all methods in a class
3. Comment and uncomment multiple lines
4. Move a code line to another line
5. Go to a method implementation
6. Automatically format the code
7. Code snippets
8. Renaming a method or a class
9. Go to a specific line
10. Bookmarks
11. Find or Replace
12. Build the project
13. Debug shortcuts
14. Save all files
15. Fullscreen mode
16. Quick action
17. Immediate window
18. Add Watch
19. Quick Watch
20. Call Stack Window
21. Find all the references
22. Organize and remove usings
23. Automatically implement interface methods
24. Minimize all items in the solution
25. Opening the Solution Explorer
26. Surronding a code
27. Automatically create a method based on the code
28. Delete/Disable all breakpoints
29. Add a new project
30. Cut the whole line
31. Extracting a method
32. Properties window
33. Error List window
34. Track a file in the solution
35. Automatically launch a Web App using an incognito page
36. Vertical selection
37. Change multiple lines at once
38. Update multiple text/variables at once
39. Navigating between open files
40. Closing a window
41. Automatically breaking a line
42. Go to your last code change
43. Paste JSON as a class
44. GitHub Copilot Chat

Searching for files or navigating between the folders within a large project can be time-consuming. However, Visual Studio provides an easy way to swiftly locate any file, type, or member within your project, for that you can press Ctrl + , or Ctrl + T and easily search for the name or part of the name:

Alternatively, you can also use Ctrl + 1 + F/T/M to search for a specific file, type or member. For example, Ctrl + 1 + F will open this window that searches for a specific file:

2. Minimize and Maximize all methods in a class

VS provides an efficient way to manage the visibility of methods within a class. This is specially useful in classes where you have a series of methods. With Ctrl + M + Oyou can minimize all methods in a class:

With Ctrl + M + L you can maximise all the methods:

3. Comment and uncomment multiple lines

To comment multiples lines at once, highlight the lines you want to comment out and pres Ctrl + K+ C:

To uncomment, press Ctrl + K+ U:

4. Move a code line to another line

If you need to move one line of code to another line, you can keep the mouse on the line you want to move, and then press Alt + Up/Down arrow:

Before
After

5. Go to a method implementation

When you want to navigate to a method implementation, if you press the key F12 you will be redirected to the interface, for example:

But if you press Ctrl + F12, then you will be redirected to the method implementation:

6. Automatically format the code

With Ctrl + K + D you can let VS format your code, for example, check the before and after running this command in the example below:

Before
After

7. Code snippets

Visual Studio also provides a feature that autocompletes the code for you.

For example, suppose you need to write a for loop, you can write for

And then press Tab + Tab, and VS will autocomplete it for you:

You can also use the prop keyword and press Tab `+ Tab, and this will create a class property:

Can also write ctor and press Tab + Tab to create a constructor:

Write exception and press Tab + Tab will create a template for an Exception implementation:

8. Renaming a method or a class

To automatically rename a method or a class, you can click on the method/class name and pres Ctrl + R + R, and add the new name:

With Enter you will rename the method, and with Shift + Enter you can preview the changes:

9. Go to a specific line

When you are working in a class and you need to go to a specific line number, you can press Ctrl + G and type the line number:

10. Bookmarks

Bookmarks are a convenient way to mark specific lines of code for quick navigation. You can use bookmarks to mark important code sections, lines that need further attention, or areas you frequently visit during development.

To set a bookmark, place the cursor on the line of code you want to bookmark and press Ctrl + K, Ctrl + K, a bookmark sign will be added to the line. For example, in the code below I created two bookmarks:

You can then press Ctrl + K + N, to navigate to the next bookmark, and press Ctrl + K + P to navigate to the previous bookmark.

To remove the bookmark, you can press Ctrl + K, Ctrl + K.

You can also view all your bookmarks by pressing Ctrl + K, Ctrl + W, or going to to View > Bookmark Window:

11. Find or Replace

When you need to search for a specific file for a specific code, you can press Ctrl + Shift + F and define your search criteria such as match case, look in the entire solution, current file, etc:

Find in Files

You can utilize the same shortcut to access the “Replace in Files” feature, which allows you to perform a replace action in an easy way:

Replace in Files

12. Build the project

To build the project, you can press Ctrl + Shift + B to quickly initiate the build process for the project:

This shortcut eliminates the need to navigate through menus, providing a fast and efficient way to compile the code.

13. Debug shortcuts

When debugging in Visual Studio, you can utilise shortcuts that can greatly enhance the debugging experience:

  • F5 start the project
  • F10 you can step over the method
  • F11 you can step into the method and
  • When debugging, you can press F5 and you can let the debug run until hit the next breakpoint
  • Ctrl + F5 you can stop the execution of the project

14. Save all files

When making changes to a file, an asterisk (*) appears next to the file name, indicating unsaved changes:

You can press Ctrl + S to save the file that you currently looking at.

When you have made changes in multiple files and want to save all these changes at once, you can press Ctrl + Shift + S:

Before
After

15. Fullscreen mode

When you want to have your code in full-screen mode, without having the solution explorer, test explorer or any other windows open, you can press Ctrl + Alt + Enter. This is a good way to keep focus only on the code you are currently working on. To go back to the normal screen, press the same shortcut.

16. Quick action

In VS, “Quick Actions” feature offers instant recommendations to enhance code quality. By pressing Ctrl + . (dot) you can access these suggestions:

You can also see it by clicking on the method name that contains these dots:

Or by hovering the mouse and clicking on the Lamp:

You can also use Ctrl + .to include the using’s you need:

17. Immediate window

The Immediate window provides a direct interface to interact with the code during debugging sessions. It can be used when debugging to inspect variables, execute code snippets, manipulate objects, etc. To access it, you can go to Debug > Windows > Immediate or press Ctrl + Alt + I:

18. Add Watch

Add Watch is a feature that allows you to inspect the state of your code at specific points in execution, allow you to monitor the value of variables, expressions, and properties during debugging sessions, and allows you to perform changes in your objects and execute code expressions.

To access it, right-click on the element you want to inspect and go to “Add Watch”:

A Watch window will be shown with the element you are inspecting:

In the example above, I’m inspecting the “categoryDto”, and while debugging I updated the property Name to “Test”, and this is reflected on the Watch window:

19. Quick Watch

Another possibility to inspect and update elements, is the Quick Watch. You can open this window by right-clicking on the element and selecting the “QuickWatch…” option, or you click on the element you want to inspect and press Shift + F9, and the following window will be shown:

20. Call Stack Window

The “Call Stack” window is quite helpful for understanding the flow of execution in your code when debugging your application. You can easily open the Call Stack window by pressing Ctrl + Alt + C :

On this window, you can see the sequence of method calls that led to the current point of execution.

21. Find all the references

quickly find all references to a specific method. This action triggers a window displaying a comprehensive list of all locations where the method is utilized throughout the project.

When you want to check where a method is being used, you can quickly find all references to a specific method. by clicking on the method name and pressing Ctrl + F12 and a window displaying a list of all locations where the method is utilized throughout the project will appear:

22. Organize and remove usings

Managing and organizing using directives within a class are good for maintaining code cleanliness and readability. With Ctrl + R, Ctrl + G shortcut, VS remove unnecessary “using” directives and sort them alphabetically:

Before
After

23. Automatically implement interfaces methods

When implementing interfaces, manually writing out all the required methods can be time-consuming and prone to errors. However, you can click Ctrl + . (dot) on the interface name and select the option “Implement interface” to significantly expedite this process.

And then all the methods will be created for you:

24. Minimize all items in the solution

When working on big projects, a solution can contain numerous folders, and when many of them are open it can become a bit tricky to navigate between them. To quickly regain clarity and focus, you can utilize the “Collapse All” feature. By clicking on “Collapse All”, all folders and their contents are minimized in the Solution Explorer, providing a concise overview of the solution’s structure:

Before
After

25. Opening the Solution Explorer

With Ctrl + Alt + L you can open the Solution Explorer without needing to go to “View” > “Solution Explorer”:

26. Surronding a code

If you need to add a line/block of code inside of a if, foreach, for, region, or any other structure, highlight the code and press Ctrl + K, Ctrl + S and select the operation you want, for example:

Highlight the code
Press Ctrl + K, Ctrl + S

For this example I choose #region, and the code was added into a region:

27. Automatically create a method based on the code

The “Generate method” feature in VS allows you to automatically create method stubs, based on types and parameters from your code, reducing manual effort. For example, you can hover the mouse in the method “CalculateArea” and press Ctrl + . (dot), and click on “Generate method ‘CalculateArea’:

A private method will be created and will take into account the return type and the parameters you specified:

28. Delete/Disable all breakpoints

Sometimes you might end up with a lot of breakpoints throughout your code, and you need to delete them. For that, you can delete all breakpoints by pressing Ctrl + Shift + F9.

Before

A confirmation dialogue will be shown asking for confirmation:

After

In case you don’t want to delete them, but only disable, you can go to the menu “Debug” > and select the option “Disable all Breakpoints:

This way they will be disabled but not deleted, and you can also enable them by going again to the same menu but then clicking on “Enable All Breakpoints.

29. Add a new project

When you need to add a new project to the solution, instead of going to the solution and right click on it and click on Add new project, you can use the shortcut Ctrl + Shift + N:

30. Cut the whole line

In order to cut a line, you can use the shortcut Ctrl + X and this will uts the entire line wherever the cursor is positioned:

Before
After

31. Extracting a method

With the shortcut Ctrl + R, Ctrl + M, you can easily extract a block of code into a separate method. For that, highlight the code you want to extract to a method:

Press Ctrl + R, Ctrl + M and type the method name:

The new method will be created:

32. Properties window

To open the property window of a file, click on the file and press F4, and the Properties window will be shown:

33. Error List window

To see errors, warnings or messages of your app, press Ctrl + \ + E and the Error List window will be shown:

34. Track a file in the solution

When you are working in a class, and you want to see this class in the Solution Explorer, instead of manuallying searching for the class in the folders, you can keep the class opened and click on “Sync with Active Document” button:

This will expand the directories and show you where the file you have it open are:

35. Automatically launch a Web App using an incognito page

When debugging an Web app, to avoid having some kind of cache issues, you can use an incognito page. For that you can set a configuration in VS to automatically launch an incognito page every time you run the project. For that, go to the “Browser With…” option:

Then add the Chrome path, and as arguments add --incognito:

Then select the new configuration:

And on the next time you run the app, it will launch on an incognito page:

36. Vertical selection

When you need to select multiple lines vertical, you can press and hold Alt and select the lines:

37. Change multiple lines at once

To replace multiple lines at once, press Shift + Alt + Up arrow and select the values you want to change:

Before
After

38. Update multiple text/variables at once

To change multiple text or variables at once, click on the text you want to change, hold Ctrl + Alt and do the change, for example:

Before
After

39. Navigating between open files

To navigate between the files you have open in Visual Studio, you can use Ctrl + Tab to swiftly switch between them:

Once you pres Ctrl + Tab you can use the arrows Up and Down to navigate between the open files.

40. Closing a window

When you have a window open, like the Immediate Window for example, you can easily close it by pressing Shift + Esc, instead of going to the X button.

41. Automatically breaking a line

When writing code and needing to break a line, instead of going to the end of the line to do that, you can use theShift + Enter shortcut. This feature allow you to break line at the cursor position, for example:

A new line was added below the current line (without breaking your code):

42. Go to your last code change

With Ctrl + Shift + Backspace you can quickly navigate back to the last location where you made a code change.

43. Paste JSON as a class

This feature is quite handy when you have a JSON structure and need to create a corresponding class for it. Instead of manually writing the classes definitions, you can make use of this feature to automatically generate the classes for you, based on the provided JSON schema.

Consider that you have the following JSON, and you want to create a class based on this structure:

{
"Title": "The Lord of the Rings",
"Author": "J.R.R. Tolkien",
"PublicationYear": 1954,
"Genres": [
"Fantasy",
"Adventure"
],
"Characters": [
{
"Name": "Frodo Baggins",
"Role": "Ring-bearer"
},
{
"Name": "Gandalf",
"Role": "Wizard"
}
]
}

For that, you can open the Program.cs class, and go to the Edit menu > Paste Special > Paste JSON as Classes:

Then the following classes will be created for you:

44. GitHub Copilot Chat

Assuming you have a Copilot license and the Copilot Chat extension (or you are using Visual Studio 2022 version 17.10 Preview 3 or later), to easily open the GitHub Copilot Chat use the shortcut Ctrl + \ + C:

[Extra] Visual Studio shortcut cheatsheet

From your Visual Studio you can easily go to the VS shortcut cheatsheet by searching for Keyboard in the Feature Search (Ctrl + .):

This will redirect you to the official Microsoft Documentation page where you find many shortcuts for VS.

Conclusion

Visual Studio is a great IDE which provides a series of features that make the code experience even better. With these tips and shortcuts, you can improve your efficiency and save time when coding.

Thanks for reading!

--

--