Visual Studio is one of the best IDE for software developers and mostly preferred by C#,.NET developers, so in this article, I have provided useful shortcuts to be used in Visual Studio like comments shortcut, collapse or expand code region etc.

Collapse all code regions

If you are working with Visual Studio from quite some time, then you must have seen there is "+" ( when code is collapsed) and "-" ( when code is alread expanded) sign, in your code which let's you expand or collapse your classes/methods code, you can collapse all the regions of the file by clicking "Ctrl+M, Ctrl+O" in Visual Studio.

Comment code shortcut

"Ctrl-K, Ctrl-C", to comment out the current selected lines

Take a look the below image, which shows how code is commented and then uncommented using Visual Studio keyboard shortcuts



You can simply use "Ctrl+K+C" to comment the current line of code or selected code.

Uncomment code block shortcut

You can use "Ctrl+K, Ctrl+U" to uncomment the selected code

Typing on Multiple Lines at Once

Yes, you can type on multiple lines at once using Visual Studio, here is the shortcut of this : Shift + Alt + ↑ / ↓ (use up arrow to select upper code lines from current selected line, and down arraow to select lower code lines)


Build Solution

"Ctrl+Shift+B" shortcut will build your solution, which is widely used by C#/.NET developers

Open Solution Explorer

Click "Ctrl+W, Cltrl+S" to open solution explorer.

Read: How to debug in visual studio? (Tutorial to debug C# code)

Ctrl+K+S to automatically add condition using shortcut

This is really excellent and loving way to add condition around the code, click "Ctrl+K+S", then you will see condition content menu, select any condition from that, here is the demo


Move Code line Up or Down

This is another interesting shortcut key, using which you can move current line of code, up or down, use "Alt+ ↑ / ↓" to do this


Find in Files (Ctrl + Shift +F)

You might need this shortcut very often, basically "Ctrl + Shift +F" open new dialog to search a term in Files.

You can even replace values if needed.

Auto Re-Format current file (Ctrl+K, Ctrl+D)

Ctrl+K, Ctrl+D : Allows you to automatically re-format the current selected document.

Search Selected Code (Ctrl+F)

Ctrl+F allow you to search for the current selected code, while Ctrl+Shift+F allows you to search complete solution

Close Current Tab (Ctrl+F4)

Use Ctrl+F4 to close the current Selected tab (file)

Close Visual Studio (Alt+f4)

You can close Visual Studio Completly by clicking Alt+f4

Open Team Explorer (Ctrl+')

To open team explorer home page click: Ctrl + '

Insert blank line above cursor (Ctrl+Enter)

Simplet click "Ctrl+Enter" to insert blank line above current cursor position


You can also use "Ctrl+Shift+Enter" to add blank line below the current cursor position.

Creating Custom Shortcuts in Visual Studio 2017/2019

You can also create your custom Shortcuts in Visual Studio as per you needs, to do this, follow these steps:

  • Go to Tools -> Options
  • Select "Keyboard" from "Envirnoment"
  • Search for command, for example, i want to create shortcut for closing solution then I will search and select "File.CloseSolution"
  • Click inside textbox of "Press shortcuts keys" and specify your combination's key. For example, click "Ctrl+Space, Ctrl+Space"
  • Click "Assign" and then ok.
  • Now you can use the new shortcut.

I will keep updating it in future, but if you have any interesting and useful VS shortcut key in mind, feel free to comment it down below.