I've been trying to improve my use of keyboard shortcuts in Visual Studio .NET. Here are the ones I use most often, what I consider my "core" keyboard shortcuts:
Go to declaration
F12
Debug: step over
F10
Debug: run to cursor
ctrl + F10
Debug: step into
F11
Debug: step out
shift + F11
Toggle a breakpoint
F9
Go to next item in task list or search results
F8
Go to previous item in task list or search results
shift + F8
Switch to code view
F7
Switch to designer view
shift + F7
Run with debugging
F5
Stop debugging
shift + F5
Run without debugging
ctrl + F5
Move to previous edit point (back)
ctrl + -
Switch to the Task List
ctrl + alt + K
Switch to the Immediate window
ctrl + alt + I
Switch to the Output window
ctrl + alt + O
Find
ctrl + F
Find in all files
ctrl + shift + F
Replace
ctrl + H
Incremental find (it's pure sex!)
ctrl + I
I'm still struggling to find a keyboard shortcut that sets the input focus back to the code window after doing a ctrl+alt+O or ctrl+alt+K. As it turns out, that key is
Esc
But enough about me. Which keyboard shortcuts do you use most often?
The best early reference for keyboard shortcuts in VS.NET 2003 was Mastering Visual Studio .NET; Appendix C contains an excellent reference table of all the keyboard shortcuts in .NET.
As good as that reference table is, you can generate a better keyboard reference yourself using my improved keyboard shortcut enumerator macro.*
It groups the results by scope and sorts by primary keyboard key so related key accelerators are all displayed together (eg, F5, ctrl+F5, shift+F5, etc).
The macro works in VS.NET 2003 and VS 2005, and unless you are a total Visual Studio Ninjatm I guarantee you'll find at least a few keyboard shortcuts in there that you didn't know about. I also did a diff on the resulting files to see what keyboard shortcuts have changed in Visual Studio 2005:
* Originally based on an earlier macro I discovered.
> I'm still struggling to find a keyboard shortcut that sets the input focus back to the code window after doing a ctrl+alt+O or ctrl+alt+K
Answering my own question, F7. I could have sworn I tried this earlier and it didn't work.
I should have also mentioned ctrl+PgUp and ctrl+PgDn which I use all the time. That switches between "tabs" at the bottom of whatever pane you're on, fex, between the HTML designer and the code view.
Jeff Atwood on June 9, 2005 7:26 PMVery nifty, thanks!
One addendum... in VS 2005 Beta 2, I had to declare all functions/subs and the _p variable as "shared" before I was able to execute List from the Visual Studio IDE.
I recall that VS 2003 allowed the direct execution of non-shared macro functions without first instantiating the class. Apparently that's no longer possible now.
Chris Nahr on June 10, 2005 4:22 AMHmm, that's interesting, it runs fine as-is on my Beta 2. It's version 55603-000-0000016-00696, whatever that means.
I would like this macro to write the HTML keyboard shortcut summary content to a new html browser window in the IDE (instead of the output console), but I lack the technical chops to do so..
Jeff Atwood on June 10, 2005 2:24 PMMacro overview tips (from PowerToys team):
http://blogs.msdn.com/powertoys/archive/2004/04/26/120763.aspx
Macro samples:
http://blogs.msdn.com/powertoys/archive/category/4817.aspx
Google search macro:
http://www.eggheadcafe.com/articles/20040423.asp
code Spellcheck macro:
http://www.codeguru.com/Cpp/V-S/devstudio_macros/article.php/c5981/
Jeff Atwood on June 10, 2005 4:30 PMGreat tips. F7 doesn't work for me though in VS.NET 2003.
My favorite VS shortcuts:
Ctrl-W (select current word under the cursor)
Ctrl-F3 (Search for current word under the cursor)
F3 (Find again - I use this all the time)
Ctrl-Tab (Next open document, you can also use this to toggle between documents like Alt-Tab does for windows)
And of course all the num keypad combinations: Ctrl-Pgup, Ctrl-Pgdn, Ctrl-Home, Ctrl-End. Can't live without them. Also I still use the num keypad instead of the arrow keys.
I've gotten used to Ctrl-Shift-B to build the current project in VS 2003, but I think the shortcut is different in the new versions I still prefer the old Ctrl-F7 (?) way of building code.
How about some useful IE shortcuts:
Alt-D (go to url address bar)
Alt-A (Favorites menu)
Backspace/Ctrl-Left (back to previous url)
Ctrl-Right Arrow (forward url)
Once you get used to certain shortcuts it becomes entirely second nature and you never go back to using the mouse.
thedisciple on June 10, 2005 11:07 PM> Ctrl-F3 (Search for current word under the cursor) F3 (Find again - I use this all the time)
Let me introduce you to my little friend CTRL+I! I rarely use F3 after finding out about this little gem known as "incremental search".
Jeff Atwood on June 11, 2005 1:54 AM>Hmm, that's interesting, it runs fine as-is on my Beta 2. It's version 55603-000-0000016-00696, whatever that means.
Looks like you got a newer version than me. Mine is the one that came on the MSDN Pro subscription DVD, and the version of Visual Basic and the other products is 55603-000-0000016-00460. The Visual Studio version is 8.0.50215.44.
If these jokers have actually updated the MSDN download compared to the DVD distribution I guess I'll have to download the Team System install, after all...
Chris Nahr on June 11, 2005 3:42 AMCtrl-I - Nice, I like the way your fingers never have to leave the keyboard while doing the search, and you can also do Ctrl-Shift-I to search backwards. Only problem is I use other editors other than VS.NET (notepad2 for one) and Ctrl-I doesn't work on the rest without additional remapping.
thedisciple on June 12, 2005 1:01 AM"I'm still struggling to find a keyboard shortcut that sets the input focus back to the code window after doing a ctrl+alt+O or ctrl+alt+K."
Shift+ESC should close the Output or any other "smaller" window and return the focus back to the code window.
Alexander Shirshov on June 12, 2005 3:20 AMCTRL+- and CTRL+SHIFT+- for navigate backward and forward. I remapped them to ALT+LEFT ARROW and ALT+RIGHT ARROW so they work like every other application that has back and forward buttons.
Patrick McElhaney on June 15, 2005 9:23 AMCtrl+- for back and Ctrl+Shift+- for forward? Isn't that the most illogical shortcut ever? Why not use Ctrl++ for forward? Semantically it makes far more sense.
Craig Glennie on July 6, 2005 7:03 PM> CTRL+- and CTRL+SHIFT+- for navigate backward and forward. forward. I remapped them to ALT+LEFT ARROW and ALT+RIGHT ARROW
You know, I totally agree with this, but.. I already use the alt+arrow combos to navigate the cursor around, so that's a showstopper!
Jeff Atwood on September 22, 2005 7:02 PMJeff,
Not sure why this is happening but in a later VS 2005 build, a command with the name "New Folder" breaks the parsing code in ParseBindings. Just changed the code slightly and everything works fine:
Dim sa() As String = Regex.Split(cmd.Name, "\.")
dr.Item("Category") = sa(0)
If (sa.Length > 1) Then
dr.Item("Command") = sa(1)
Else
dr.Item("Command") = ""
End If
Interesting. NewFolder is the *only* command like that-- it has a category but no command (?). This is new to the PDC build of VS.NET 2005.
Your bugfix is totally correct though. I'll update the code snippet.
Jeff Atwood on October 5, 2005 7:31 PMWell, I found the CTRL+M - CTRL+O and CTRL+M - CTRL+M shortcuts quite handy to collapse to definition/expand region under cursor ...
Also for large blocks I'm using CTRL+K - CTRL - C and CTRL+K - CTLR - U fairly often for Comments, but the latter two differ in different language versions of VS.
The CTRL+- is something I really missed quite often after browsing through a big class and then searching for my last edit point ... and ended up using UNDO-REDO to find my way back ;)
Testingstuff on October 11, 2005 6:44 AMCant use CTRL+PgDn/CTRL+PgUp in VS2003 - for me is simply navigate between top of page and bottom. What I missing? Maybe because I use laptop.. Actialy I looked something for switch between editor tabs in next/prev order but not in history like CTRL+TAB/CTRT+Shift+TAB?
Alex Tretyakov on November 14, 2005 1:38 AMThanks all for the tips.
So far in the release version of VS 2005, you can switch to code view from the HTML using F7, but from code view shift F7 no longer works to return you to HTML view, boo. You have to right click, select design, then Control + Page Up to get back.
Am keeping my fingers crossed for the service pack.
hth
omhoge on January 4, 2006 9:53 AMI guess I'm a visual person so I think they broke Ctrl+Tab in 2005. I don't want to read a list of file names. I want to see the next in a series of forms and/or code and I want to do it quickly. I use Ctrl+F6 and Ctrl+Shift+F6 now, but it took me a while to find the new way to do things.
Will on January 17, 2006 12:19 PMi am BE(info tech)student so plase send me samples of vb.net code and projects on it and i
want get codes on text to speech,and network monitoring tool
I mention this on another entry here but I made a program that makes it easier to remember keyboard shortcuts for Visual Studio and other programs too. So hope it helps someone here and always appreciate feedback on how we can improve. Thanks. <a href="http://www.ghostclip.com">http://www.ghostclip.com</a>
Curtis
In case anybody is interested, I created a Studio Shortcut Cribsheet that categorizes the most useful (IMO) Visual Studio shortcuts into one page. It's posted on my blog.
Carl Camera on February 6, 2006 10:15 AMhow to clear the contents of immediate window using a shortcut key ?
Vinod on May 8, 2006 6:25 AMI've used Ctrl-Shift-B to build the current project in VS 2003,I prefer the old Ctrl-F7 way of building code.
ravi varma on May 15, 2006 10:31 PMomhoge:
I use this litlle macro to switch to markup from the code.
Just bind it to your favorite shortcut (like shift-f7 in the text editor).
Sub SwitchToMarkup()
If (DTE.ActiveWindow.Caption().EndsWith(".cs") Then
Dim FileName = DTE.ActiveWindow.Document.FullName.Replace(".cs", "")
If System.IO.File.Exists(FileName) Then
DTE.ItemOperations.OpenFile(FileName)
End If
End If
End Sub
Ctrl+F2 takes you to the navigation bar!
helps me a lot ...
I'm gonna try posting this here in the off-beat chance it might get a response. On previous vs.net installations, if I had several classes open, as I ctrl-tab'd through them or clicked on them manually with the mouse, the project explorer would automatically highlight the current item being edited. It doesn't happen anymore!! This behavior only shows on my work PC and my home PC. My work PC is a brand-new install of visual studio.net 2003 enterprise. I was surprised to see it happening on a brand new install.
Does anybody have any ideas what might be wrong and how I can fix this? It is so much easier to keep track of where I am when the project explorer window automatically highlights the selected file :-(
Andres on July 19, 2006 11:28 AMTo "stand on the shoulders" of Mikael H's great little macro, I've extended it to toggle back & forth between markup & the source code. Coming from a Delphi background, if you bind the macro to F12 you'll feel right at home and developing with speed!!
Sub SwitchToMarkup()
Dim FileName
If (DTE.ActiveWindow.Caption().EndsWith(".cs")) Then
' swith from .aspx.cs to .aspx
FileName = DTE.ActiveWindow.Document.FullName.Replace(".cs", "")
If System.IO.File.Exists(FileName) Then
DTE.ItemOperations.OpenFile(FileName)
End If
ElseIf (DTE.ActiveWindow.Caption().EndsWith(".aspx")) Then
' swith from .aspx to .aspx.cs
FileName = DTE.ActiveWindow.Document.FullName.Replace(".aspx", ".aspx.cs")
If System.IO.File.Exists(FileName) Then
DTE.ItemOperations.OpenFile(FileName)
End If
ElseIf (DTE.ActiveWindow.Caption().EndsWith(".ascx")) Then
FileName = DTE.ActiveWindow.Document.FullName.Replace(".ascx", ".ascx.cs")
If System.IO.File.Exists(FileName) Then
DTE.ItemOperations.OpenFile(FileName)
End If
End If
End Sub
Also, regards alt-tab being "broken" by Microsoft, did you know you can go to the Tools/Options/Keyboard and remap Alt-Tab from being bound to "NextDocumentWindowNav" to plain old "NextDocumentWindow" and it'll be how it was before (no pop-up window on alt-tab)
Lozza on July 19, 2006 7:13 PMAndres..
Go to Tools->options->Projects and Solutions->General and check "Track active item in solution explorer
I find it very useful too...its turned off by default not sure why?
Yogesh on August 8, 2006 3:51 PMAnother one I use - Ctrl-Shift-F9 for clearing all breakpoint. After you've been debugging something down a looong path and you're ready to move on.
Will Lynn on August 11, 2006 6:02 AMAbsolutely incredible... It ll help me lot.
sanjay rokade on August 22, 2006 5:44 AMOne thing that seems to be missing (unless I'm just reading over it) is a way to jump to the end of an XML tag. When using the XML documenting in VS 2005, if I'm working on a list of things, it's a real pain to have to grab the mouse when I'm finished in a tag.
Lee Crabtree on August 29, 2006 7:13 AMthank advance. Now i try find short cut key using in visual studio.
kimsea on August 30, 2006 6:49 PMhow to clear the contents of immediate window using a shortcut key ?
Vinod on May 8, 2006 06:25 AM
"> cls" does it in vs2005.
how to clear the contents of immediate window using a shortcut key ?
Vinod on May 8, 2006 06:25 AM
">cls [enter]"
To collapse all blocks Ctrl-M-O very helpful.
Also with keyboard to expand a block #Region xyz [...] Press Space and right arrow and it will expand.
Rob Blij on October 17, 2006 4:06 AMYou should use Resharper :)
Diego on October 20, 2006 8:05 AMAnyone know the shortcuts to trigger the class or method dropdowns in the c# editor?
Lancer on October 24, 2006 12:12 AMSome of the most used.. just in case some one is refering http://sumtechstuff.blogspot.com/
sri on November 3, 2006 2:52 PMI like the CTRL+M, CTRL+M. I use regions extensively. This opens and closes the region on the cursor.
I use CTRL+R,CTRL+E a lot, too.
Robert Bouillon on November 8, 2006 8:15 AMI use ctrl + M, ctrl + O quite often (to collapse code) so that I can see where I am.
Organize organize.
Brian on November 25, 2006 1:21 PMI also use ctrl + M, ctrl + O quite often, but I would really like to know the reverse shortcut (expand all). I have to scan visually and expand manually. This is very tedious, since an expanded block can itself containned a collapsed block.
Anonymous on December 12, 2006 2:07 PMCtrl-k-k (hold down Ctrl and press k twice) - Inserts a bookmark on your cursor's line
Ctrl-k-c (hold down Ctrl and press k then c) - Comments out the current or selected lines
I would like to know if there's a shortcut to disable the current breakpoint--for times where you just want to disable the breakpoint on the fly
Yoder on December 13, 2006 6:42 AMTo Reverse collapse of your regions (expand all), you can use CTRL+M, CTRL+P.
Alicia on December 29, 2006 9:32 AMHi.
Do you know what the syntax for ALT+TAB would be in C++? Sort of like browsing through your windows applications.
Thanx
Marius on January 14, 2007 11:39 PMAny idea on how to remove what seems to be an "embedded" keyboard command when you are in a SQL Server query designer? The undocumented keyboard "shortcut" is Shift-Space which moves the cursor focus to the first column of the row and selects the row.
I ask because if you are typing CAPS and hit the spacebar, this "shortcut" becomes unproductive! Any ideas on how what this shortcut is or how to remove it? Not in the keyboard mapping within Visual Studio, at least not showing.
Thank you!
For ages I searched for a key to set focus to the heading style combo (block format combo) when editing in VS's html editor. Couldn't find one but here's a macro that does it. Bind a keystroke to it and it works great...
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports Microsoft.VisualStudio.CommandBars
Imports System.Diagnostics
Public Module Module1
Public Sub FocusToSyleCombo()
' Get the formatting commandbar and make sure its visible
Dim cb As CommandBar = DTE.CommandBars("Formatting")
cb.Visible = True
' Set focus to the block format combo
cb.Controls("Block Format").SetFocus()
End Sub
End Module
bradr on March 7, 2007 4:39 PMHere is a nice cheat sheet (PDF) of VS keyboard shortcuts.
http://iamacamera.org/default.aspx?section=home&id=43
Eric D. Burdo on March 28, 2007 5:17 AMMarius, ctrl+tab works in vis studio, at least in c#, wouldn't think it'd be dif for c++.
Alicia on April 24, 2007 10:31 AMHi guyz, tnx alot for all the info, but could anyone tell me how can I navigate between functions definitions in C++ in vs2005? I mean something like to go to next function body and go to previous function body.
tnx.
Jefe on April 30, 2007 9:43 AMCtrl - (hyphen) is good for navigating back to where you were in your code, Ctrl Shift - to go in other direction. Ridiculously useful.
Ctrl Shift R to record a series of keystrokes, Ctrl Shift R again to stop recording... Ctrl Shift P to play
Ctrl ] (square bracket) is useful to find matching brace in Javascript
Sean on May 18, 2007 2:35 PMMay 27, 2007
Good work!
The major mistake was made by IBM and Microsoft over 20 years ago, moving function keys on the standard keyboard from a two-column, left-side pod to a row above the main pod, adding clutter with the redundant navigation pods and "Windows" keys. Making the function keys hard to use was followed by gradual abandonment of function-key mappings by software products.
We retained several high-quality keyboards from prior years, and we map to them, providing, for example, single-stroke, non-chorded keys for the most frequently used functions: copy, cut and paste. That alone brings a typical 1-2 percent productivity increase.
in the editor...
1)Instead of deleting back to the period...
Ctrl+Space brings up list of an object's properties and methods
Instead of deleting back to the parentheses...
Ctrl+Shift+Space brings up list of an function's parameters
Chuck Hall on August 21, 2007 1:47 PMCtrl + Right : Autocomplete the current member via intellisense. Do it just after a dot to see all available choices.
zootius on August 31, 2007 3:14 AMKeyboard shortcuts are the best. Once you start using them, you really can't stop. Since I've even been implementing them into my ie surfing, it's quite a breeze using ie quickly. Generally, I'll open up a number of tabs and use
ALT D – to get to the url bar, then type in the address
CTRL TAB – to switch between tabs
Then I can also just use the arrow keys to move up and down the page. Only problem is, that if you're commenting on someone's blog (like here) TAB generally doesn't work the most efficiently. You really have to use the mouse in that case. But otherwise, it's great not having to use the mouse for everything – especially on my laptop, as the plastic fades away easily.
toys on October 1, 2007 6:44 AMstumbled on this whilst trying to find a keyboard shortcut to get back to the code window since f7 doesnt work anymore.
try ctrl-tab.
A few nifty shortcuts i love are:
ctrl + . to bring up that code smart tag which adds in missing using statements or fully qualified names.
another great one is if you highlight a class field and hit ctrl + r, e (the chorded style shortcut). It makes that field a property. :D
Thanks, Rob, for the Control-M-O thing, I was going crazy looking for the NUM key on my laptop because the references I read said it was num - .
You really saved me lots of effort!
I just learned Ctrl-. (or Shift-Alt-F10) today.
That is the coolest one ever.
Type Regex and hit Ctrl-. and <Enter>.
using System.Text.RegularExpressions;
was automatically added to your using section.
Do you know how many times I went to the help to try to remember what object things were under (like Path.[System.IO] or Process.[System.Diagnostics] or Color.[System.Drawing]?
PRMan on November 29, 2007 9:53 AMAnyone who knows how to collapse all nodes of the Solution Explorer and vice versa.I have 50-60 projects and collapsing/expanding them one by one is a pain.
Thanks
raj:
http://geekswithblogs.net/scottkuhl/archive/2007/04/09/111195.aspx
@raj:
Search for CoolCommands 3.0 . The macro that is presented on http://geekswithblogs.net/scottkuhl/archive/2007/04/09/111195.aspx is quite slow.
Finding matching End If in VB.net (Equivalent c # find matching brace)
Hi people - in short there is no such functionality in VB.NET. So here a little macro I wrote to do the Job !
Put the cursor on the 'end if' and it finds the 'if'. Put it on the 'if' and it finds the 'end if'
I simply re- map 'CTL ]' to the marcro with 'Use New Shortcut In:' setting to text editor
---------------------------------------------------------------------
Private Function CleanLine(ByVal sLine As String) As String
sLine = sLine.ToUpper
sLine = sLine.Replace(vbTab, "")
sLine = sLine.Trim()
Return sLine
End Function
Sub FindBrace()
Dim bFoward As Boolean
Dim bIfCount As Integer = 1
Dim o As TextSelection = DTE.ActiveDocument.Selection
Dim sLine As String
o.DTE.SuppressUI = True
o.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText)
o.SelectLine()
sLine = CleanLine(o.Text)
Select Case True
Case sLine.StartsWith("IF ")
bFoward = True
Case sLine.StartsWith("END IF")
Case Else
Exit Sub
End Select
Do
If bFoward Then
o.LineDown(False, 0)
Else
o.LineUp(False, 1)
End If
o.SelectLine()
sLine = CleanLine(o.Text)
Select Case True
Case sLine.StartsWith("IF ")
If bFoward Then
bIfCount += 1
Else
bIfCount -= 1
End If
Case sLine.StartsWith("END IF")
If bFoward Then
bIfCount -= 1
Else
bIfCount += 1
End If
End Select
Loop Until bIfCount = 0
o.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText)
o.LineUp(False, 1)
o.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText)
End Sub
-----------------------------------------------------------------
tony F on January 18, 2008 2:20 AMUse Ctrl + numpad * to 'pop' a goto definition location jump (i.e. takes you back to where you were when you did a 'goto definition' (F12)
MGB on April 1, 2008 3:01 PMis there any keyboard short cut to select multiple lines?
Lancer asked this question a long time ago, and i have the answer.
------------------------QUESTION------------------------------
Anyone know the shortcuts to trigger the class or method dropdowns in the c# editor?
Lancer on October 24, 2006 12:12 AM
-------------------------ANSWER--------------------
CTRL+F2+TAB
CTRL+F2 highlights the Types dropdownlist and then the tab moves your to the Members dropdownlist.
I was going mad not knowing a shortcut for this one so i decided to use the god old Trail and Error.
Torving on July 1, 2008 3:21 PMthanks for the complete list of keyboard shortcuts!
COOL!! :))
In Visual studio.net, Microsoft seems to have taken away the ability to map the NUM keys to commands, which I have previously used extensively while debugging. I was forced to map all my commands, for example, to use ALT+NUM+ instead of simply NUM+. This is very annoying since I must now hold down the ALT key continuously while debugging.
Does anyone know how to get access to the NUM keys for assignment?
Bob H on October 8, 2008 8:31 AMspecified your codes.
make it applicable.
thanks...
-kristian
If you want to be listing of visual studio 2008 Keyboard Shortcuts than go through this URL
:)
Many thanks for this informations
shaju on June 24, 2009 6:04 AM| Content (c) 2009 Jeff Atwood. Logo image used with permission of the author. (c) 1993 Steven C. McConnell. All Rights Reserved. |