Visual Studio Tips and Tricks: 5 great keyboard shortcuts

Visual Studio Tips and Tricks: 5 great keyboard shortcuts

Rate This
  • Comments 3

VisualStudioLogoHere’s five of my favorite keyboard shortcuts in Visual Studio, I think there’s a good chance there is at least one of them you haven’t seen before!

Find more Visual Studio tips and tricks here

Move code ALT+UP/DOWN

This keyboard shortcut is new in Visual Studio 2013. If you put the cursor on a line of code and use the <ALT><UP ARROW> key the line of code you have selected moves up. If you use the <ALT><DOWN ARROW> the line of code selected moves down.

 

 

Create Collapsible Region CTRL+M+H/CTRL+M+U

Chances are you have noticed the “+” and “-“ symbols in the margins that allow you to collapse and expand your classes and functions. Did you know you can create your own collapsible regions? If you select a section of code and then use the key sequence <CTRL><M><H> you turn that region into a collapsible/expandable region. The key sequence <CTRL><M><U> will remove the collapsible region (it doesn’t delete the code, it just removes the icon that allows you to expand and collapse.

 

 

Comment code block CTRL+K+C/CTRL+K+U

Whether it’s because you are trying to track down a but, or experimenting with code change, from time to time you will want to comment and uncomment blocks of code. If you select a block of code and use the key sequence <CTRL><K><C> will comment out the section of code. <CTRL><K><U> will uncomment the code.

 

Peek Definition ALT+F12

When you are going through your code and you want to examine the code in the method you are calling, many programmers will use the <F12> key or the pop-up menu option Go To Definition. Go To Definition will navigate to the called method, however many times you don’t need to navigate to the code. Sometimes, you just want a quick look at the method. If you have installed Visual Studio 2013 there is a new keyboard shortcut <ALT><F12> which will give you a preview of the method being called inline. You can use the <ESC> key to close the preview.

 

 

Navigate Forward/Backward CTRL - /CTRL SHIFT -

When you have multiple files open at the same time you may want a way to quickly move back and forth between two or three different locations in your code. If you have moved from one location to another you can use the keyboard sequence <CTRL><-> to move to the previous location and then you can return using <CTRL><SHIFT><->

 

Where do I get Visual Studio 2013?

Students can download Visual Studio 2013 Professional at DreamSpark

MSDN subscribers can download it from MSDN

Anyone can get express versions of Visual Studio for free or 90 day trials of Visual Studio Professional, Premium, or Ultimate at the Visual Studio downloads center.

Learn more about the new features of Visual Studio by watching the Visual Studio 2013 New Features at Microsoft Virtual Academy

Leave a Comment
  • Please add 8 and 1 and type the answer here:
  • Post
  • These are great.  There should be a shortcut to create regions (#region) similar to the collapsible areas.

  • Yes but Natigate Back does not work properly. It navigates back to every little place your cursor ever touched. Many times, for example, I am using Find to locate a method or property. After I have found it, I make some changes and then I press Ctrl+- to navigate back. And I have to sit through useless jumps around the file from the time I was doing the Find. Same across files: I am editing something in one file, then open another and move the cursor a little bit up and down to find where I am going to edit. Then, after making a change, I want to navigate back to the file I came from. But Ctrl+- never works. It first takes you through every place your cursor landed in the current file, before finally going to the previous file. It's useless.

  • @Shaggygi - that would be nice!

    @Nic - You might want to check out tasks and bookmarks as alternatives if you don't like the way Navigate works... Tasks in particular are kind of cool as a way of marking points in code you want to return to...  I often use //TODO don't forget to go fix this and then in the Task List windows make sure you can view Comments.

Page 1 of 1 (3 items)