views:

8979

answers:

116

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.

+23  A: 

Ctrl+K, Ctrl+D // Auto-(Re)Format

See Also: Answer

Nescio
Particularly useful for messy XML files.
Damian Powell
+16  A: 

I like Ctrl+M, Ctrl+M. To expand/collapse the current code block.

Adam Neal
+13  A: 

Solution Explorer: Ctrl+Alt+L

SaaS Developer
Nice! ... how do I get back?
Svish
I usually hit "Esc" to get back.
SaaS Developer
+41  A: 

Stock Visual Studio? F12 - Edit.GoToDefinition.

Having DevExpress' Refactor! installed means that Ctrl-` is my all-time fave, though ;)

moobaa
-1, favor http://stackoverflow.com/questions/98606/favorite-visual-studio-keyboard-shortcuts/98826#98826 (But second CodeRush, though I tie it to Num 0)
Ruben Bartelink
+21  A: 

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.

spoon16
This is for View.SHowSmartTag so any smart tag that appears will have their menu openw ith this (e.g., implement interface). I change this mapping to Alt+Down arrow.
Mark Cidade
I tend to hit Windows button -> down -> right -> enter, which to me is faster than repositioning my hands in a weird way in order to press Shift+Alt+F10+Enter.
Rahul
Great comments guys! Thanks!
spoon16
You can do Ctrl + "." for the same purpose, and it's much, much more comfortable.
asterite
Yes, you can do Ctrl+".", but the original Shift + Alt + F10 will also work in other MS applications such as Outlook, PowerPoint, Excel and Word.
0xA3
-1 as dup of one above (even if this was first, not surte if it was)
Ruben Bartelink
+59  A: 

Expand Smart Tag (Resolve Menu): Ctrl + . (period)

Expands the tag that shows when you do things like rename an identifier.

Ray
Best shortcut ever. Use when you see a squiggly "~", under some code. : )
Chad Moran
This is my fave and only one I can remember. Alt-Enter is similar if you have resharper installed.
Daniel
I would give this +10 if I could.
geofftnz
Also Shift-Alt-F10 is bound to this but probably harder
Ruben Bartelink
Good shortcut, but what it actually does is bring up the "Resolve" menu (so you can add a `using` statement or fully qualified namespace for a class)...it has nothing to do with tooltips.
DanM
DanThMan, you're right, tooltip isn't the correct terminology, will update
Ray
+5  A: 

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.

Jon Schneider
And dont forget you can arrow left in the popup to go to tool windows too....
Ruben Bartelink
Another way to do this is to use Alt+W+2. This is go back and forth. Also allows for 3 way action using Alt+W+3, if you can remember the right order.
Robin Robinson
amof, I hate this feature. It *makes me think*.
Lieven
+98  A: 

Ctrl + - and the opposite Ctrl + Shift + -

Move cursor back (or forwards) to the last place it was. No more scrolling back or PgUp/Dwn to find out where you were.

Ctrl + tab

Switches open windows in VS.

Glennular
This is made even better when you bind them to 'application specific' back and forward mouse buttons!
Joe
I've been looking for this forever. I used to just use Ctrl+Z Ctrl+Y.
Paul Alexander
Ctrl-Tab is a bit funny in VS for some reason - it doesn't just cycle like most apps.
Lucas Jones
@Lucas Jones, It seems to cycle like Alt-Tab in Windows. Seems normal to me.
DanM
Pressing Ctrl + Tab once swaps between the current document and previous document, you don't even need to look at the popup window.
Ash
I often cancel cycling between application windows (Alt+Tab) by pressing Esc. Doing so while cycling through document windows (Ctrl+Tab), however, pops up Windows' start menu. That just drives me nuts.
sbi
+32  A: 

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.

nzpcmad
Fantastic - knew about snippets, but not that you could get to them so quickly!
xan
this. is. awesome...
Alex. S.
+15  A: 

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.

fatcat1111
I use <menu key>, <g> for go to definition. Its much easier to reach than F12. <menu key>, <a> will do find all references, too. Most of the time when I'm browsing code, I have my left hand on keyboard and my right hand on the mouse, which means I can right click and press <g> or <a> for these as well, which is pretty quick.
Tim Coker
+5  A: 

Ctrl+R+T (Runs the current test)

Ctrl+R+A (Runs all tests in the project)

Ian P
Do you seriously know all these by heart?
DanM
I wish there were a way to pop up the test results panel...
Tim Coker
+1  A: 

Ctrl+Shift+B - Build

ben
-1: Dup of http://stackoverflow.com/questions/98606/favorite-visual-studio-keyboard-shortcuts/99126#99126 (Even if it breaks the 'one' request)
Ruben Bartelink
+72  A: 

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.

Dara Kong
Plus, it finds the first instance as you type. Ctrl-i after you hit a match searches to the next instance - and keeps you in search mode (which means you can add or change the search string). The search box is for suckers!
Aardvark
That's cool, I didn't know that, although I had on some occasions hit ctrl+I by mistake and wondered what the odd mouse pointer meant. :)
pipTheGeek
One caveat with this that I've seen (in VS 2005 any way), it only searches through visible text. So if you have some collapsed in a region, for example, it won't search that. I don't know if this is a feature or a bug!
Adam Neal
Sounds like the emacs search feature.
dicroce
@Adam: In my experience, the fact that VS ignores hidden text (e.g. inside collapsed regions) makes this feature almost useless. Incremental search is an awesome feature, I just with they hadn't crippled it in VS.
CodeSavvyGeek
@CodeSavvyGeek: It's fixed in VS2010.
TheCloudlessSky
A: 

Use Emacs-like keybinding, it's TAB :P

+24  A: 

Ctrl+] for matching braces and parentheses.

Mark Cidade
A: 

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.

Hamish Smith
I think default was "Alt+Shift+F10"... Mine was overwritten by Resharper...
Sung Meister
+4  A: 

Ctrl+I for incremental search

phloopy
It's Ctrl+I not an "L": fixed
Sung Meister
Dup of http://stackoverflow.com/questions/98606/favorite-visual-studio-keyboard-shortcuts/98846#98846
Ruben Bartelink
+1  A: 

Ctrl + Alt + E = Exception/Catch Settings and code snippets

RobS
+1 Didn't know this one.
280Z28
A: 

Ctrl+Shift+S // Save

Ctrl+Shift+B // Build

Dan Coates
-1: Already individually upvoted
Ruben Bartelink
+14  A: 

CTRL+F5 (Start Without Debugging)

CTRL+SHIFT+B (Build Solution)

Giorgio Galante
F7 is "build solution" for me.
korona
+13  A: 

Ctrl+M, O. Can collapse and expand all sections of code in a particular file.

I suggest a cheat sheet, by the way:

I have these things as well as the Resharper cheat sheet by my desk permanently.

Russell Myers
Thanks for the Cheat Sheets
Maudite
VS O8 link has been removed from the destination site. It says, due to possible copyright infringement.
John Dunagan
It's not Ctrl+M,0 but Ctrl+M,O (<- not zero but an O)
Sung Meister
A: 

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

Wayne
+50  A: 

Ctrl+K, Ctrl+C Comment a block

Ctrl+K, Ctrl+U Uncomment the block

tdyen
Ctrl+K, CTRL+U also comments a block.
Maudite
Ctrl K, D formats the entire document (proper indents, ws cleaned up, etc.) in mine. ?
John Dunagan
I typically customize the mapping to be CTRL+/ (comment) and CTRL+SHIFT+/ (uncomment). I find that nice and intuitive.
ee
Ctrl-E, C and Ctrl-E, U also works. You dont have to release Ctrl after the first key either.
geofftnz
/ in CodeRush also does this
Ruben Bartelink
I use CTRL+/ withy Resharper.Resharper_LineComment which with one shortcut toggles line comments on and off.
Myster
+1  A: 

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.

Jerph
C-F5 is dup. Alt D P is alternative for Ctrl Alt P
Ruben Bartelink
A: 

Ctrl+K then Ctrl+H to add a line of code to the built in task/todo list

(Ctrl+Alt+K). Very handy!

amdfan
+11  A: 

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)

Jerph
This could also be annoying if you press Ctrl+C by mistake instead of Ctrl+V
shoosh
And CodeRush adds even more w/ Ctrl W and auto stuff on Ctrl-C....
Ruben Bartelink
Now *that* one I like. +1
DanM
+33  A: 

Ctrl+Shift+F

Good old Find In Files.

unforgiven3
Wow, finally a shortcut that I already knew ;)
Jess
+5  A: 

If 'Favorite' is measured by how often I use it, then:

F10 : Debug.StepOver

:)

Scott Ferguson
+20  A: 

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.

Control-L cuts the current line. Control-Shift-L deletes it.
Greg
Wow.. "Ctrl+/" is awesome...
Sung Meister
@Greg: Class, thanks. @Others: These are great ones, but fail to adhere to the questioner's one per line ask :- -1 :(
Ruben Bartelink
Also dup of http://stackoverflow.com/questions/98606/favorite-visual-studio-keyboard-shortcuts/101873#101873
Ruben Bartelink
Ctrl + D duplicates the current line as well (and much shorter)
Ray
Ctrl+/ is great. Anyone know if there are any good docs on the commands I can use with this?
Damian Powell
@Ray: Ctrl + D isn't working for me. Is that with default Visual Studio shortcuts? It might be a ReSharper shortcut IIRC?
dariom
Yeah, I realised later (and updated my answer, but not my comment) that it's a resharper shortcut.
Ray
+1  A: 

Ctrl+[ (Move to corresponding })

Ctrl+Shift+V (Cycle clipboard)

Jeremy Reagan
+1  A: 

There are some great tips and trips and shortcuts on Sara Ford's blog.

JasonS
+5  A: 

By far the most useful (after Ctrl+Shift+B) are:

  • Ctrl+K, C - to Comment out selection

  • Ctrl+k, U - to Uncomment a selection
Don
In VS 2008 selection is Ctrl+E C to comment and Ctrl+E U to uncomment. I like them along with Ctrl+E D to reformat.
Si
Dup of http://stackoverflow.com/questions/98606/favorite-visual-studio-keyboard-shortcuts/99276#99276
Ruben Bartelink
A: 

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.

+2  A: 

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.

  • Ctrl+E, C: Comment Selected Text

  • Ctrl+E, U: Uncomment Selected Text

  • Ctrl+W, E: Show Error List

  • Ctrl+W, J: Show Object Browser

  • Ctrl+W, S: Show Solution Explorer

  • Ctrl+W, X: Show Toolbox

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.

Shabbyrobe
That Ctrl+K, S is awesome!!!. Coupled with successive Ctrl+W and you have a winner for fast coding.
Alex. S.
+13  A: 

Ctrl+Shift+V paste / cycle through the clipboard ring

Wedge
I've always found this feature too slow to be of any use. I wish they would improve its performance - sometimes its takes up to 20 seconds to load the items in the clipboard.
cbp
Use clipx if you want to do clipboard history. It spans all applications. http://www.bluemars.org/clipx/
Tim Coker
A: 

Ctrl+Shift+8 - Backtracks go to previous "F12/ Go to definition"

vzczc
Ctrl + Shift + 7 is the complementary shortcut to do that - go fwd to next Go To Def invoked in the chain.
Gishu
+55  A: 

For me, it's nothing 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 ;)

Pablo Marambio
I always use Alt+V, U for the same effect :) But yeah fullscreen mode rocks.
korona
BIG monitors work too =)
Jess
This is great, I have never seen this one before. Thanks.
Robin Robinson
Agreed! I use this one all the time. VS10 will have floating panels which will help somewhat.
Paul
Having all the extra windows unpinned when in edit mode helps too.
CodeSavvyGeek
A: 

Ctrl+- and Ctrl+Shift+-. But if you are a keyboard lover then go for Resharper

-1:Duplicate upvoted
Ruben Bartelink
A: 

Ctrl+X

This deletes the current line of code.

Morten Christiansen
Extra powerful w/CodeRush
Ruben Bartelink
This "cuts" the line. Ctrl+ L for delete.
Alex. S.
+3  A: 

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

Germstorm
+4  A: 

Ctrl+F10

run to cursor when debugging. Looked for this for ages before I found the keyboard shortcut...

Joel in Gö
+1  A: 

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.

Joel in Gö
Me too!! I collapse to definitions, then drill down with Ctrl+M+M: Toggle Outlining Expansion
Tor Haugen
+29  A: 

Ctrl+Space, VS gives the possible completions

siri
A: 

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...

RWendi
All duplicates AFAICT
Ruben Bartelink
+3  A: 

The combination Ctrl+F3 and Ctrl+Shift+F3 for finding selected and previous selected item works very well for me.

Henk Marquering
A: 

Another useful Find short key sequence is Ctrl (+ Shift) F --> ALT C --> ALT W for switching between exact and fuzzy searches.

Henk Marquering
+2  A: 

F9: toggle and un-toggle breakpoints!

JohnIdol
A: 

Save LOTS of time copy and cutting:

  • Ctrl+C with no selection in the line: copies the whole line

  • Ctrl+X with no selection - cuts the whole line
RoyOsherove
Duplicate AFAICT
Ruben Bartelink
only it was written BEFORE the other one. thanks!
RoyOsherove
+1  A: 

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.

I Like Shift+F11
Sung Meister
A: 
Mladen
Duplicate AFAICT
Ruben Bartelink
A: 

Ctrl+K, Ctrl+D - Format the current document.

Helped me fix indentation and remove unneeded spaces quickly

Dror Helper
A: 

"prop" and hit tab.. stubs out property for you...

CSharpAtl
A: 

Ctrl+M, Ctrl+L will expand every collapsed bit of code. It is the opposite of Ctrl+M, Ctrl+O

Franck Mesirard
A: 

Turn line wrapping on and off

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.

Herb Caudill
A: 

Format document

   Ctrl+K, Ctrl+D
  1. 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.

  2. In your C# or VB code, this will correct any capitalization or formatting issues that didn't get caught automatically.

  3. 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.

Herb Caudill
A: 

Refresh javascript intellisense and code coloring.


ctrl+shift+J

I've found intellisense for Javascript to be flaky - this usually straightens it out.

Herb Caudill
+1  A: 

Find and replace

  • Ctrl+F and Ctrl+H - Find, Find & replace, respectively

  • Ctrl+shift+F and Ctrl+shift+H - Find in files, Find & replace in files, respectively

"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.

Herb Caudill
And then F8/Shift-F8 to step the results
Ruben Bartelink
A: 

Outlining

  • ctrl+M, ctrl+M - Collapse/expand current element

  • ctrl+M, ctrl+O - Collapse all (gives you a nice overview of a complex class, for example)

  • ctrl+M, ctrl+O - Toggle all

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:

  1. Go to the first line

  2. ctrl+M, ctrl+M to collapse it

  3. ctrl+X to cut it (you don't have to select it, as long as your insertion point is still in that line)

  4. Move to where you want it and ctrl+V to paste.
Herb Caudill
+2  A: 

Cutting and pasting lines

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.

Herb Caudill
I'm floored by how many people don't know/use this. I'm also floored that the C# editor team still can't get the cursor placement correct.
280Z28
+1  A: 

Commenting

  • ctrl+K, ctrl+C - Comment current item

  • ctrl+K, ctrl+U - Uncomment current item

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.

Herb Caudill
A: 

Snippets

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.

Herb Caudill
On my VS2008 the default is prop{TAB}, not property.
Ash
+2  A: 

Showing hidden windows

  • ctrl+alt+L + Solution explorer

  • ctrl+alt+S + Server explorer

  • ctrl+alt+O + Output

  • ctrl+alt+X + Toolbox

  • ctrl+shift+W, 1 + Watch

  • ctrl+\, E + Error list

  • ctrl+shift+C + Class view

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.

Herb Caudill
Or you could just remember one shortcut: Shift + Alt + Enter
Ash
+3  A: 

Ctrl+Alt+P -> Attach to process

Chris Ballance
+1  A: 

F7 toggles from design view to code view.

Maudite
A: 

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!

+1  A: 

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.

You must be using an add-in because stock Visual Studio doesn't do this. I actually wrote (and still use) an add-in that does this.
280Z28
@280Z28: Works for me in VS 2008.
sbi
A: 

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

CheGueVerra
ctrl +'-' goes back to the last line your cursor was on in my VS
johnc
+7  A: 

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!

J Francis
A: 

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)

Think these are all dups (and questioner asked for 1 per answer)
Ruben Bartelink
A: 

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.

Gishu
e.g. the find in files results
Ruben Bartelink
and Shift F8 in reverse order
Ruben Bartelink
+1  A: 

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

korona
+10  A: 

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..

Gordon Hartley
This is awesome!!! (shift+esc) I always build, have the output window fly out and have the mouse cursor hovering, which prevents it from autohiding. This makes me move my hands off the keyboard, which I HATE. But thanks to this, you've solved my single biggest annoyance with visual studio. THANK YOU THANK YOU THANK YOU.
Tim Coker
+4  A: 
Keith Elder
or alt when mouse selecting
Ruben Bartelink
horizontal text selection
hIpPy
+1  A: 

F7 to build and then F8 to go to the errors and warnings one by one.

Atempcode
A: 

Hmmm, nobody said F1 for help.

Could it be that Google is faster and better for getting at the information that you need.

Ron Todosichuk
Hit F1, make a coffee, go to google, type in your query (one finger typing), fully read each search return on the first 3 1/2 pages, find your answer and fix the code, catch a train home, do the cryptic crossword, have a beer, sleep in, go to work and have a coffee, check your pc, and wait ...
johnc
... wait for it ...
johnc
... wait for it ...
johnc
... Visual Studio 'F1' Help has finally opened!
johnc
... I am still waiting...
Sung Meister
There's nothing more frustrating than accidentally hitting F1
hacker
... Wow, my 'F1' help has finally opened.!!!
Sung Meister
Perhaps F1 should just open a browser pointed at Google in a Visual Studio tab. I love how Google is better at finding reference materials than most web site's own searches (and most application's built-in references in this case).
Triynko
+3  A: 

Alt + B + U - Build the current project.

etsuba
Wow.. I didn't totally wasn't aware of this shortcut...
Sung Meister
Or Shift F6 in the C# bindings
Ruben Bartelink
Technically speaking, I think this should be 'Alt, B, U'.
Damian Powell
A: 

VS 2008

  1. Ctrl+E,D : Format Code

  2. Ctrl+M,O : Collapse To Definitions

  3. Ctrl+Z : Undo :)

  4. F9: Breakpoint

  5. Ctrl+Shift+F9 : Delete All Breakpoints

+1  A: 

Some handy ones that I use often are:

Ctrl+J -> Forces Intellisence to pop up.

Ctrl+Alt+L -> Show the Solution Explorer.

Jeroen Landheer
+2  A: 

Select word: Ctrl+W

I can't live without that shortcut. Used over 100+ (or 200+) a day.

Sung Meister
The interesting thing is that it selects up on hierarchy. For example, within a block if you press Ctrl+W, it first select the word near to, if you press Ctrl+W again, now it selects the surrounding block and so on.
Alex. S.
A: 

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

Aaron Saarela
A: 

Ctrl+Shift+F4 to close all windows. You have to map it yourself:

Instructions:

  • In Visual Studio, go to Tool | Options
  • Under Environment select Keyboard
  • In Show commands containing, enter Window.CloseAllDocuments. You should get a single entry in the listbox below it
  • Put the cursor in Press shortcut keys and press Ctrl+Shift+F4.
  • Click OK

Credit to Kyle Baley at codebetter.com. I modified his example to use shift instead of alt because it was easier on my hands.

Eric Bock
I bind this to Ctrl+W (close window) and Ctrl+Shift+W (close all windows) to match several other programs.
280Z28
+15  A: 

VS 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:

http://www.codinghorror.com/blog/archives/000315.html

Jeff Atwood
+4  A: 

Ctrl+Shift+S

Save all changed files. saved me quite a few times.

shoosh
A: 

Alt+F4 ;)

But on a more serious note, Ctrl+Space is probably hit a lot from me, in my limited usage of VS.

aCiD2
-1: Duplicate (even if this was first, the other is upvoted)
Ruben Bartelink
A: 

I've mapped File.Close to CTRL+SHIFT+W. That and CTRL+TAB mean you can close exactly whichever files you want.

Jonathan Parker
A: 

Ctrl+Shift+R -> Refactor with Resharper

Chris
+1  A: 

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!

Tor Haugen
I see Sung Meister lists the same command, but with a different key combination. Myself, I use the Visual C# environment settings, I guess he doesn't.
Tor Haugen
A: 

Here are my favourite debugging keyboard shortcuts:

  • F5 : start debugger / run to next breakpoint
  • Shift+F5 : stop debugging
  • F10 : step over next statement
  • F11 : step into next statement
  • Ctrl+F10: run to the cursor location
  • F9 : add or remove breakpoint
Phillip Ngan
+2  A: 

Ctrl + BP (Previous bookmark), Ctrl + BN (Next bookmark)

Rashmi Pandit
+1  A: 

Insert snippet:

Ctrl+K, Ctrl+S

I use if often for try..catch and #region

callisto
+1  A: 

Im a big fan of Ctrl+D+Q to open quickwatch while debugging.

OG
Does it make you hungry for ice cream? :D
DanM
That's terrible. Love it.
OG
A: 

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

Ruben Bartelink
+1  A: 

Ctrl-Shift-Space shows the syntax/overloads for the current function you are typing parameters for.

Maslow
A: 

Paste in loop Ctrl + Shift + V

Expand Collapse current block - Ctrl + M + M

Code Snippet - for creating property type prop and press tab.

Mahin
+1  A: 

Here is a list that I use frequently:

Ctrl + i : for progressive search. If you don't type anything after 'i', and keep pressing 'i'(holding the CTRL key down), it will search the last item you had searched. Ctrl + Shift + i will reverse search. You might also want to use F3 (and Shift + F3) once some search string is entered.

Ctrl + k Ctrl + c : For commenting highlighted region. If nothing is highlighted, current line will be commented. Naturally, you can just hold Ctrl and press k,c in succession.

Ctrl + k Ctrl + u : For uncommenting highlighted region. Works like above.

Ctrl + / : Will take the cursor to the small search box on top. You can type ">of filename" (without the quotes) to open a file. Very useful if your project contains multiple files.

Ctrl + k Ctrl + k : Will bookmark the current line. This is useful if you want to look at some other part of code for a moment and come back to where you were.

Ctrl + k Ctrl + n : Will take you to the next bookmark, if there are more than one.

Ctrl + - : Will take the cursor to its previous location

Ctrl + Shift + - : Will take the cursor to its next location (if it exists)

Ctrl + Shift + b : Build your project

Ctrl + c : Although this does the usual copy, if nothing is highlighted, it copies the current line. Same for Ctrl + x (for cut)

Ctrl + Space : Autocomplete using intellisense

Ctrl + ] : Will take you to the matching brace. Works with all kinds of braces: '(', '{', '['. Useful for big blocks.

F12 : Will take you to the function definition/variable definition.

Alt+p+p : Will open up project properties. Although not many use this, it useful if you want to quickly change the command line arguments to your program.

F5 : To start debugging

Shift + F5 : To stop debugging

While debugging, you can use Ctrl + Alt + q to add a quick watch. Other debugging shortcuts can be found in the debug drop down menu.

Ashwin
This one has a few I didn't know yet and a few I use regularly.
sbi
+3  A: 

By usage, the pair:

  • Ctrl+Enter: insert blank line above the current line.
  • Ctrl+Shift+Enter: insert blank line below the current line.
280Z28
CTRL + ENTER inserts above the current line on my VS2008.
Ash
Oops, I had them backwards. :o I don't even think about it anymore. :)
280Z28
This is simple, but very useful.It could save a lot of keystrokes, thank you.
CMinus
A: 

Ctrl+Shift+V multiple times cycles through the clipboard ring.

280Z28
+1  A: 

Control+Apostrophe.

Oh wait, that was after I remapped it away from that god-awkward Alt+Shift+F10 or whatever it was.

When you remap options to help bind this away from it's original hard to hit shortcut, it becomes a lot lot more useful.

MiffTheFox
Really? i *love* Alt-Shift-F10!
RCIX
@RCIX - To clarify, I love what Alt+Shift+F10 does, but I don't love how hard it is to hit compared to Ctrl+Apostrophe.
MiffTheFox
Posting just the keys themselves is pointless. Most (sensible) people don't know what Alt+Shift+F10 because they've always used Ctrl + .
Ash
+3  A: 

Ctrl + I for incremental search

@FooBar : What does it mean? Incremental Search?
odiseh
@odiseh : Incremental search is where you start typing, and the selection keeps jumping to the first match of whatever you've typed so far. It usually saves you keystrokes, since you can just start typing until you've found what you're looking for. It also doesn't pop up a dialog.
Scott Smith
+2  A: 

Ctrl+W for selecting the current word

it says this one is a chord...
Steve
A: 

Ctrl+D Duplicate current Line (Resharper only)

Ray
Doesn't do that.. at least in VS2008.
James Jones
oh my mistake. It's a Resharper shortcut.
Ray
Sorry dude, but it's not working
CMinus
Will only work with resharper, it's a default shortcut though.http://www.jetbrains.com/resharper/docs/ReSharper40DefaultKeymap.pdf
Ray
A: 

It's simple, but

Ctrl + L

deletes the entire line. Great for fast code editing.

Paul
A: 

Ctrl + M, L - Expands all regions

Evan
A: 

I don't think that any shortcut is remaining for me to mention so let me mention a shortcut that I would love Visual Studio to have :-) One shortcut that I really miss and that is present in Eclipse is "Open Resource" (Ctrl + Shift + S) which allows you to type in a file name and the IDE displays the files matching it. Really useful when you are working with bid code bases!

Aayush Puri
See [Ctrl+/](http://stackoverflow.com/questions/98606/favorite-visual-studio-keyboard-shortcuts/1441130#1441130).
sbi
+1  A: 

The combination Ctrl+u and Ctrl+Shift+u for converting a block of characters to all upper/lower case.

Marcus Lindblom
A: 

Ctrl+A, K, F

Select all, prettyprint.

James Jones
+1  A: 

Ctrl + K + C - set current selected code to be comments Ctrl + K + U - set current selected comments to be code

deype0
A: 

Shift+Del deletes the whole line.

It's the first keyboard combination that I discovered with Jedi Senses. Later I felt a disturbance because it flushes the clipboard.

Ufuk Hacıoğulları
That only works if the correct option is set. It annoys me, so I have turned it off. It might be on by default, though, I don't remember.
sbi
+3  A: 

Open a newline above Ctrl + Enter

Open a newline below Ctrl + Shift + Enter

Kev
That's a nice one!
sbi
A: 

I mapped all of the expand/collapse commands so that they can be used with the left and only so my right hand stays on my mouse. CTRL+E, CTRL+E toggles expansion, CTRL+E, CTRL+D collapses all to definitions, CTRL+E, CTRL+A toggles all outlining.

Tim Coker
Funny, I always prefer my hands to stay on the keyboard and try not to use the mouse. (The down-vote isn't mine, though.)
sbi
99% of the time i keep my hands on the keyboard, too. But there are times when I'm studying code that its convenient to have a hand on the mouse and being able to expand/collapse with just my left hand is very useful.
Tim Coker
+3  A: 

Haven't seen this one ...

Ctrl + Up

Ctrl + Down

Scrolls the window without moving the cursor.

Tim Coker
A: 

People have mentioned Ctrl+C and Ctrl+V to paste a line when nothing is selected but I use Ctrl+X to move lines of code regularly.

aboes81
A: 

Hopefully this hasn't already been posted, apologies if so. I've just come across a useful keyboard shortcut in Visual Studio 2008. With the QuickWatch window open, highlight a row with a string value in it and hit Space Bar. The text visualiser window will appear with the value in it.

I have found it quite useful for checking jQuery innerText values as the QuickWatch window by default is too small to show longer strings fully.

Malice
A: 

i not run with Microsoft way so i use my own shortcut. i customize then i feel my development better and easier

steven spielberg
yeah but don't you hate it when you switch to another computer and all your keyboard bindings aren't there
qntmfred
i thing you forget to make backup of setting.
steven spielberg
+3  A: 

Surround With

CTRL + k , s

great when you want to wrap some text in a tag

TheLukeMcCarthy