Shortcuts in Visual Studio that are Trump Cards in Coding

Every time you work on your system you need some shortcuts and that's why we have some basic ones like:

  • Cut
  • Copy
  • Paste

But for the developer working on Visual Studio then he need some more shortcuts to increase their productivity so I will explain how to do the code easily and reduce your time to write the code.

Perhaps you know them but it's necessary for every developer to use them. That's why they are added to Visual Studio. Due to them Visual Studio is becoming a very powerful IDE for developers.

Here are some of them:

  1. Ctrl + K + D
  2. Shift + Alt + Up Arrow / Shift + Alt + Down Arrow
  3. Ctrl + M + O
  4. Ctrl + M + M
  5. Ctrl + K + C
  6. Ctrl + K + U
  7. Ctrl + F / Ctrl + H

To learn more in details, see the following.

Ctrl + K + D

This is my favorite shortcut and It's a very useful shortcut for "Formatting" either in a code file or .aspx file. For example when code is unformatted or is unstructured then just press "Ctrl + K + D" and see the magic.

Before "Ctrl + K + D" in the code file:



After pressing "Ctrl + K + D" in the code file:



Note: You can do the the Same in an .aspx file.

Shift + Alt + Up Arrow / Shift + Alt + Down Arrow

This shortcut is used when you have some continuous lines and they all have something in common, either in the code file or .aspx file like initials, now you want to change them with a single change using s replace all because it will replace that word in the entire page but you want to change some continue lines only like here.

Before "Shift + Alt + Up Arrow / Shift + Alt + Down Arrow". Now you want to change the "void" to "int" in all methods.



After "Shift + Alt + Up Arrow / Shift + Alt + Down Arrow":



This shortcut combines the cursors in a single cursor for all selected rows, that you can see in the preceding image as a vertical line after an int.

Note: You can do the Same in an .aspx file.

Ctrl + M + O

This shortcut collapses all the methods or classes in a single line or you can say it collapses each panel of code for the child and parent both. it will not work in an .aspx file.

Before "Ctrl + M + O":



After "Ctrl + M + O":


Note: You can't do this in an .aspx file.

Ctrl + M + M

This shortcut is used when you want to collapse the current span and you can also expand the current span. You can use this in a code file and .aspx file both.

Like here before "Ctrl + M + M":



After the first "Ctrl + M + M" when the cursor is in the A1() method:



After the second "Ctrl + M + M" when the cursor is in the A1() method:



Note: You can do this in .aspx file.

Ctrl + K + C

This is one of my favorite shortcuts that are used for commenting the selected code, either in the code file or .aspx file. The following are some key points of this shortcut.

  • If you use it in a code file then it comments the code in a single line at once like '//'.



After the "Ctrl + K +C":

  • If you use it in an .aspx file then it comments the code in multiple lines at once like '<%--'



After the "Ctrl + K +C":


Ctrl + K + U

It un-comments the selected code, either in a code file or .aspx file. The following are some key points of this shortcut.

  • If you use it in a code file then it uncomments the code in a single line manner like "//'



After the "Ctrl + K +U":



Note: It doesn't work with multiple comments that are like "/* */".

  • If you use it in an .aspx file then it comments the code in multiple lines at once like "<%--" .


After the "Ctrl + K +U":


Ctrl + F/ Ctrl + H

It is very common for a key combination used for a find and replace of any content in the file, but in Visual Studio you can use this in various variants like the following you can see:



"Ctrl + F" is only used to find the contents in the selected variant where as "Ctrl +H" is used for a find and replace of the content in the selected variant.

Note: It works in all kinds of files.

Conclusion: I hope they will be beneficial for you as a developer.

 


Similar Articles