What is your favorite Visual Studio keyboard shortcut? I'm always up for leaving my hands on the keyboard and away from the mouse!
One per answer please.
What is your favorite Visual Studio keyboard shortcut? I'm always up for leaving my hands on the keyboard and away from the mouse!
One per answer please.
Ctrl + - and the opposite Ctrl + Shift + -.
Move cursor back (or forwards) to the last place it was. No more scrolling back or PgUp/PgDown to find out where you were.
This switches open windows in Visual Studio:
Ctrl + tab and the opposite Ctrl + Shift + tab
For me, it's nothing to do about auto completing code, matching parenthesis or showing some fancy tool panel. Instead, it's just about letting me see the code.
With all the panels surrounding you, the area you use to actually write code becomes too small.
In this cases, Shift+Alt+Enter comes in to the rescue and gets the code window in focus in full screen mode. Hit it again, and you have all the panels back.
Incremental Search - Ctrl + I
It's basically the find dialog box without the dialog box. Just start typing what you want to search for (look at the bottom status bar location to see what you've typed). Pressing Ctrl + I again or F3 searches for the next instance. Press Escape to quit. Starting a new search by pressing Ctrl + I twice repeats the last search.
Expand Smart Tag (Resolve Menu): Ctrl + . (period)
Expands the tag that shows when you do things like rename an identifier.
Stock Visual Studio? F12 - Edit.GoToDefinition.
Having DevExpress' Refactor! installed means that Ctrl + ` is my all-time fave, though ;)
The TAB key for "snippets".
E.g. type try and then hit the tab key twice.
Results in:
try
{
}
catch (Exception)
{
throw;
}
which you can then expand.
Full list of C# Snippets: http://msdn.microsoft.com/en-us/library/vstudio/z41h7fat.aspx
Ctrl+] for matching braces and parentheses.
Ctrl+Shift+] selects code between matching parentheses.
Ctrl+C, Ctrl+V to duplicate the current line
Ctrl+L to delete the current line
Ctrl+F3 to search for the current selection
Ctrl+K, Ctrl+K to create a bookmark (which are useful)
Ctrl+K, Ctrl+N to go to the next bookmark
And, here is something even more interesting:
Press Ctrl+/ to put the cursor into a box where you can type commands.
For example, Pressing Ctrl+/ and type ">of ", now start typing the name of a file in your project, and it will autocomplete. This is a very fast way to open files in the current solution.
One that I use often but not many other people do is:
Shift + Alt + F10 then Enter
If you type in a class name like Collection<string> and do not have the proper namespace import then this shortcut combination will automatically insert the import (while the carret is immediately after the '>').
Update:
An equivalent shortcut from the comments on this answer (thanks asterite!):
Ctrl + .
Much more comfortable than my original recommendation.
Shift+ESC
This hides/closes any of the 'fake window' windows in Visual Studio. This includes things like the Solution Explorer, Object Browser, Output Window, Immediate window, Unit Test Windows etc. etc. and still applies whether they're pinned, floating, dockable or tabbed.
Shortcut into a window (e.g. Ctrl + Alt + L or Ctrl + Alt + I) do what you need to do, and Shift + Esc to get rid of it. If you don't get rid of it, the only way to give it focus again is to use the same keyboard shortcut (or the mouse, which is what we're trying to avoid....)
Once you get the hang of it, it's immensely useful.
Grrr....The amount of times of hit Ctrl + F4 to close the 'window' only to see my current code window close was insane before I found this, now it only happens occasionally..
My favorite: F12 (go to definition) and Shift+F12 (find references).
The latter is useful with F8 (go to next result).
Ctrl+- and Ctrl+Shift+- are mapped to my mouse's back and forwards buttons.
Ctrl+. is useful too, especially for adding event handlers and "using" statements.
Visual Studio 2005/2008 keybinding posters:
These don't cover customizations, but they're good reference materials and definitely helpful for finding new shortcuts.
Also, a macro that dumps all the current bindings to a HTML file:
Alt+Shift+arrow keys(←,↑,↓,→)
This allow you to select things in a block. Like you could select all of the "int" in the block and then search and replace to double for example.
**int** x = 1;
**int** y = 2;
**int** z = 3;
One that other editors should take up:
Ctrl+C with nothing selected will copy the current line.
Most other editors will do nothing. After copying a line, pasting will place the line before the current one, even if you're in the middle of the line. Most other editors will start pasting from where you are, which is almost never what you want.
Duplicating a line is just: Hold Ctrl, press c, then v. (Ctrl+C, Ctrl+V)
Ctrl+F10
run to cursor when debugging. Looked for this for ages before I found the keyboard shortcut...
Good old Ctrl+Tab for flipping back and forth between open documents.
Visual Studio actually provides a very nice Ctrl+Tab implementation; I especially appreciate that the Ctrl+Tab document activation order is most-recently-used order, rather than simple "left-to-right" order, so that Ctrl+Tab (press once and release) can be used repeatedly to flip back and forth between the two most-recently-used documents, even when there are more than two documents open.
By far the most useful (after Ctrl+Shift+B) are:
Ctrl+Shift+R Tools.RecordTemporaryMacro (again to stop recording)
Ctrl+Shift+P Tools.RunTemporaryMacro
Beats the heck out of trying to work out a regexp search and replace!
I like my code clean and arranged so my favorite keyboard shortcuts are the following:
Ctrl+K,D - Format document
Ctrl+K,F - Format selected code
Ctrl+E,S - Show white spaces
Ctrl+L - Cut line
Alt+Enter - Insert line below
I hate closing the extra tabs when I use "Start Debugging" on ASP.NET apps. Instead, I usually use "Start without Debugging" (Ctrl+F5).
If I end up needing to debug, I use Ctrl+Alt+P (Attach to Process)
and choose WebDev.WebServer.exe. Then I'm still on my previous page and I only have one tab open.
The combination Ctrl+F3 and Ctrl+Shift+F3 for finding selected and previous selected item works very well for me.
Everyone knows Ctrl + X and Ctrl + C for cutting/copying text; but did you know that in VS you don't have to select the text first if you want to cut or copy a single line? If nothing is selected, the whole line will be cut or copied.
I like to use all my screen real estate for code and have everything else hidden away. These shortcuts keep these windows handy when I need them, so they can be out of the way the rest of the time.
Ctrl+Shift+space shows the syntax/overloads for the current function you are typing parameters for.
F7 and Shift+F7 to switch between designer/code view
Ctrl+Break to stop a build.
Great for those "oh, I realized this won't compile and I don't want to waste my time" moments.
Alt+Enter opens the resharper smart tag
Bookmark ShortCuts
Ctrl+K Ctrl+K to place a bookmark
Ctrl+K Ctrl+N to go to next bookmark
Ctrl+K Ctrl+P to go to previous bookmark
The refactor shortcuts.
Each starts with Ctrl+R.
Follow it with Ctrl+R for rename. Ctrl+M for extract method. Ctrl+E for encapsulate field.
If you have your keyboard settings set to the "Visual C# 2005" setting, the window switching and text editing chords are excellent. You hit the first combination of Ctrl + Key, then release and hit the next letter.
I still use F4 to show the properties pane so I don't know the chord for that one.
If you go to the Tools > Customise menu option and press the Keyboard button, it gives you a list of commands you can search to see if a shortcut is available, or you can select the "Press Shortcut Keys:" textbox and test shortcut keys you want to assign to see if they conflict.
Addendum: I just found another great one that I think I'll be using quite frequently: Ctrl+K, S
pops up an intellisense box asking you what you would like to surround the selected text with. It's exactly what I've needed all those times I've needed to wrap a block in a conditional or a try/catch.
The great thing about this is that it applies to the element you're currently in - you don't have to select a whole line of VB code to comment it, for example, you just type Ctrl+K, Ctrl+C to comment the current line. On an aspx page, you can comment out a big chunk of code - for example an entire ListView - by just going to the first line and hitting Ctrl+K, Ctrl+C.
Some handy ones that I use often are:
Ctrl+J -> Forces Intellisence to pop up.
Ctrl+Alt+L -> Show the Solution Explorer.
Ctrl + K + C - set current selected code to be comments Ctrl + K + U - set current selected comments to be code
Ctrl+M, Ctrl+O : collapse to definitions. I use it all the time together with #regions
(despite what Jeff says) to get an overview of the code on my screen.
I just found out that Shift+F11 steps out of the current function.
This is very useful when you want to debug function foo in foo(bar(baz()). Use F11, Shift+F11 to jump in and out of bar and baz.
Alt+Shift+ Arrow keys(←↑↓→) or mouse moving = Block/Column selection
comes really handy
"Find in files" has been an enormous productivity booster for me. Rather than jump to each result one by one, it just shows you a list of results in your entire project or solution. It makes it very simple to find sample code, or see if a function is used anywhere.
Not a keyboard shortcut, but with your mouse, you can use forward and backwards buttons on your mouse to go to previous locations in your code and return to your current location.
If you install Visual Assist X, which I highly recommend you do, these are useful:
Alt+O: Toggle current document between header/implementation (.h/.cpp)
Alt+G: Go to definition/declaration
Alt+F4 ;)
But on a more serious note, Ctrl+Space is probably hit a lot from me, in my limited usage of VS.
Ctrl+ E + D : Format Document
Tip for teams: Set up agreed-on formatting options in Visual Studio (they are very flexible), then export the settings to a .settings file for each developer to import.
Now if all developers learn to autoformat everything, it will not only produce perfect formatting consistency throughout the project with no effort at all, but also greatly reduce annoying false differences in the diff tool when merging multiple check-ins to Source Control.
Oh, I enjoy good tools!
What Ray said. Ctrl + ..
I really didn't like the smart tags (those little blue and red underscores that appear wanting to help you) until I found out that you don't need to waste time trying to hover the mouse over the exact pixel that gets the menu to show.
I think Ctrl + . to open the smart tag menu saves me about five minutes every day and reduces my blood pressure considerably.
I have two that I use a lot, the first is standard, the second you have to map:
Ctrl+A, Ctrl+E, F (Select All, Format Selection)
Ctrl+E, R (Remove Unused Usings and Sort)
Both help pay down the "cruft debt" early and often
Ctrl+K then Ctrl+H to add a line of code to the built in task/todo list
(Ctrl+Alt+K). Very handy!
Nothing beats Ctrl+Shift+B - Building the solution!!
As far as navigation control, Ctrl+- and Ctrl++ is nice...
But I prefer Ctrl+K+K ---> creates bookmark...
and Ctrl+K+N ---> to navigate to the next bookmark... awesome stuff...
Another useful Find short key sequence is Ctrl (+ Shift) F --> ALT C --> ALT W for switching between exact and fuzzy searches.
Save LOTS of time copy and cutting:
Ctrl+K, Ctrl+D - Format the current document.
Helped me fix indentation and remove unneeded spaces quickly
Ctrl+M, Ctrl+L will expand every collapsed bit of code. It is the opposite of Ctrl+M, Ctrl+O
Ctrl+E, Ctrl+W
Sometimes you want to see the flow of the code with all of your indents in place; sometimes you need to see all 50 attributes in a GridView declaration. This lets you easily switch back and forth.
Ctrl+K, Ctrl+D
On an aspx page, this takes care of properly indenting all of your markup and ensures that everything is XHTML compliant (adds quotes to attributes, corrects capitalization, closes self-closing tags). I find that this makes it much easier to find mismatched tags and to make sure that my markup makes sense. If you don't like how it's indenting, you can control which tags go on their own line and how much space they get around them under Tools/Options/Text Editor/HTML/Format/Tag Specific Options.
In your C# or VB code, this will correct any capitalization or formatting issues that didn't get caught automatically.
For CSS files, you can choose compact (one definition per line), semi-expanded, or expanded (each rule on its own line); and you can choose how it handles capitalization.
ctrl+shift+J
I've found intellisense for Javascript to be flaky - this usually straightens it out.
This works both in VB/C# code (e.g. collapse/expand a function) and in an aspx page (e.g. collapse/expand a GridView definition).
One very nice use of this is to cut or copy a big chunk of markup or code: For example, to move a big, sprawling <table> or <asp:gridview> definition:
Each snippet has a shortcut that you can access by typing a word then tab. The one I use the most is for a standard property definition; just type property then tab.
Open a file without using the mouse:
CTRL + ALT + A (opens command window) Followed by >open somedoc
I didn't see this one yet. Can't believe how many cool shortcuts have been posted here!
Here's a link to a list of Shortcuts I find usefull (VS2003) but some still apply,
My favorite being F12 and Ctrl+- to navigate to the declaration and back
Ctrl+- and Ctrl+Shift+-
Alt+D, P
Attach the debugger to the application.
(first letter of any application you want to debug, works most of the time)
Ctrl+Shift+F
Ctrl+I (incremental seach)
Simple one. F8 : Go to next build error.
Found that now it will work in any sort of list window (the ones that cluster together at the bottom usually.
Hmmm, nobody said F1 for help.
Could it be that Google is faster and better for getting at the information that you need.
VS 2008
The ones I use all the time:
ctrl+] Matching Brace
ctrl+shift+] Select to the end of brace
ctrl+shift+q Untabify
ctrl+k,ctrl+c comment out the currently selected block
ctrl+k,ctrl+u uncomment out the currently selected block
alt+mouse move vertical selection
ctrl+alt+x toolbox
ctrl+shift+b build
Ctrl+Shift+F4 to close all windows. You have to map it yourself:
Instructions:
Credit to Kyle Baley at codebetter.com. I modified his example to use shift instead of alt because it was easier on my hands.
I've mapped File.Close to CTRL+SHIFT+W. That and CTRL+TAB mean you can close exactly whichever files you want.
Here are my favourite debugging keyboard shortcuts:
I'm addicted to some very subtle stuff in http://blog.jpboodhoo.com/UsefulVSKeySequencesShortcuts.aspx
e.g. Alt-W U to auto collapse everything when in Full screen mode when it all gets too much