Since we got so many comments with lots of useful information on our Visual Studio Shortcuts post we decided to use those comments and some other shortcuts we found and compile another list so lets get going
CTRL + “K” + “M”: This one is Genius.
Incase you need to add a method to an
already existing class you just write the method
as if it exists :
1: int i = 5;
2: bool flag = NewMethod(i);
Click on the shortcut and you will get the
following method stub:
1: private bool NewMethod(int i)
2: {
3: throw new NotImplementedException();
4: }
Great isn’t it?
1: int i = 5;
2: bool flag = DifferentClass.NewMethod(i);
Put the cursor on the new method, click the shortcut and you will see this:
Hit Enter and you will get a new method stub with the return value and the parameter, in the other class.
1: public class c
2: {
3: internal bool NewMethod(int i)
4: {
5: throw new NotImplementedException();
6: }
7: }
Definitely my favorite.
CTRL + “-” and CTRL + SHIFT + “-”: These two are similar to the Forward and Backwards buttons of the WebBrowsers and will take you to all the places your curser was, Very useful for those times you click F12 to go to definitions and then have no clue where you were before :). (Thanks Vijay Santhanam).
ALT + ENTER: We talked about it in the last post, but it seems that this shortcut will open the properties window on anything that moves, even Files in your Windows Explorer. (Thanks to Bryan Migliorisi from http://www.Migliorisi.com).
SHIFT + ALT + ENTER: This one will switch you Visual Studio to Full Screen mode, which is very useful in those boring presentation when you have to show your code through a projector on a screen. Another click will get you back to normal mode. (Thanks to Pablo Marambio).![]()
CTRL + “M” + “M”: This one will collapse the region your cursor is at whether its a method, namespace or whatever for collapsing code blocks, regions and methods. The first will collapse only the block/method or region your cursor is at while the second will collapse the entire region you are at. (Thanks to knave).
CTRL + ALT + “P”: This will open up the attach to process window, very useful for debugging. (Thanks Greg Beech from http://gregbeech.com).![]()
CTRL + “R” + “R”: This one is used to quickly rename a method/ variable or whatever. (Thanks again to Greg Beech).![]()
F8 and SHIFT + F8: These two are great! they are similar to the shortcut number 3 but they will take you forward and backwards in your search results just search for something and then start hitting F8 and you will see. (Thanks to David Hu).
CTRL + SHIFT + “B”: This one will invoke build solution. ( Thanks to Matt Brunell).
CTRL + “B” + “T”: This one will allow you to quickly add or remove a bookmark from a line of code.
Truly some great and helpful shortcuts. Thanks to everyone who commented, and looking forward to hearing what else you have.
If you want some more cool options for your visual studio check out Power Commands. And once again if you think we missed anything, comment.
Enjoy.
Amit.
speps Said on May 6, 2008 :
So the first one also introduces typos?
“private bool NewMethos(int i)”
Just kidding, great shortcuts.
chris Said on May 6, 2008 :
I noticed that you try to hide the article when Adblock is enabled. I think that extremely annoying. The first few times I clicked on a link to your site, I thought “what a ****” there isn’t even an article, just a lot of bla bla. Looked like some kind of link farm without content…
You should at least show are warning that users disable Adblock. Else they’ll just move on and never visit your site again. Ever.
configurator Said on May 6, 2008 :
Ctrl-”.”: I always use Alt-Shift -F10 in my work, which is the same.
It also helps with renaming (in the definition of a method/variable/class/whatever, change the name and the little box will appear. Press ctrl-”.” or Alt-Shift-F10, and it will suggest the rename operation).
And with completing namespaces (e.g. type
namespace TheNamespace { class Thing { } }
namespace OtherNamespace {
class OtherThing {
void doit() {
Thing x = new Thing();
}
}
}
, put the cursor on one of the Things in the line Thing x = new Thing();, and it will suggest the completion)
Ctrl-”B”-”T”: Also Ctrl-”K”-”K”.
And I have a question about Ctrl-”-”: I use that a lot. But I also always accidentally pres the back button on my IBM Thinkpad keyboard (because it’s right next to the direction keys - very annoying).
Visual studio then goes to some obscure file or another, but I never figured out how it decides where to go. Also, the same with the forward button.
Kimmen Said on May 6, 2008 :
Ctrl + M + O, similar to number 6 but does it to alla collapsable regions in the document.
F2 does the same thing as Ctrl + R + R.
Shahar Y Said on May 6, 2008 :
Chris,
Although we are not happy with you using adblock, we are not trying to hide anything when Adblock is enabeled. Moreover, we tested Dev102 with adblock and it works fine. There must be something else that causes you to not see our posts. Can you add more details?
Hector Said on May 6, 2008 :
Everytime I try to use the “Ctrl + K + M” shortcut Visual Studio says the command is not available at the moment. Why? I’ve tried selecting the whole function call, part of it, etc and no success.
I’ve not been able to use the second one either.
Mahesh Kumar R Said on May 6, 2008 :
thanks amit.
Regarding Tip # 11:
For bookmark alternatively you can use,
CTRL + “K” + “K” ( for add and Remove)
Amit Said on May 6, 2008 :
@ Mahesh
are you certine that your cursor was on the method call?
Scott Said on May 6, 2008 :
Same problem as Mahesh. Neither 1 or 2 work for me. Generate Method Stub is disabled, even if I add a toolbar button for the same command.
Brian Lowry Said on May 7, 2008 :
I’m a big fan of CTRL + K + C and CTRL + K + U for commenting and uncommenting code… seems to work everywhere but CSS stylesheets.
Sam Said on May 9, 2008 :
Great article, some new ones there for me. On the subject of expanding regions, Ctrl + “M” + “L” will expand all collapsed sections in the current file.
If the code file doesn’t contain any collapsed sections, each section will be collapsed. This isn’t so handy as it collapses all collapsable sections, not just regions.
Brian Canzanella Said on May 21, 2008 :
My favorite is Ctrl+Shift+F9 which will delete all breakpoints.
Mark Sowul Said on May 21, 2008 :
For CTRL-R, R - another alternative is the usual Windows rename shortcut, F2.
Amit Said on May 21, 2008 :
I did not know about the F2 option, Very nice! Thanks Mark
AI Said on May 22, 2008 :
To expand on shortcut #2 - using ‘Ctrl’ + ‘.’ after Type names (or anytime you see a tiny block under what you just typed) also provides a different context menu e.g. if you use it after the class name Path (from System.IO) it will display a context menu with the option to either include the System.IO namespace or use the fully qualified name i.e. System.IO.Path. Very useful when you are using classes that you haven’t referenced yet.
Thanks for the shortcut list. Some of them that I didn’t know about are going to be real time savers especially Ctrl + Alt + P.
Jan Wikholm Said on Jun 6, 2008 :
Hello,
Just a tip for #3 - if you have a mouse with the forward/back buttons (such as Logitech MX510) you can use those instead of the keybindings
Mohan Said on Jun 12, 2008 :
There is one great book available in infoQ Please read…..
Visual Studio .NET Tips and Tricks explains how to use VS.NET efficiently. Organized into short and easy-to-grasp sections, and containing tips and tricks on everything from editing and compiling to debugging and navigating within the VS.NET IDE, this book is a must-read for all .NET developers, regardless of expertise and whether they program in C#, VB.NET, or any other .NET language. This book covers the Visual Studio .NET 2002, 2003, and 2005 Beta 1 releases.
http://www.infoq.com/resource/minibooks/vsnettt/en/pdf/vsnettt_infoq.pdf
sxd Said on Jun 23, 2008 :
Hi,
I’m having some kind of weird thing with my VS2008. It opens TWO instances fo IE when I hit CTRL+F5 in order to run an app. Never happened before. Now I can’t change it. Any idea?
Thanks!
Shahar Y Said on Jun 24, 2008 :
Hi sxd,
Try to see how the Ctrl+F5 is customized in your VS2008. Check this page http://msdn.microsoft.com/en-us/library/bb245788(VS.80).aspx and read the Customizing Keyboard Shortcuts section. Hope that will help…
John Said on Sep 3, 2008 :
Can anyone post the shortcut for generating the getters and setters for a property. thanks
Shahar Y Said on Sep 3, 2008 :
@ John
Print “prop” and then hit TAB+TAB (hit twice on TAB) and you get it.
It is important to mention that this is not a keyboard shortcut but a code snippet.
SunKwon Kim Said on Oct 12, 2008 :
These shortcuts are useful to me.
Especially, No.2 and No.8 shortcuts are cool.
http://www.wpfstory.com/entry/11-More-Visual-Studio-Shortcuts-and-one-additional-shortcut-you-shold-know