Favorite Visual Studio keyboard shortcuts

Viewed 129775

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.

124 Answers

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.

Ctrl+K, Ctrl+C Comment a block

Ctrl+K, Ctrl+U Uncomment the block

Stock Visual Studio? F12 - Edit.GoToDefinition.

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

Ctrl+] for matching braces and parentheses.

Ctrl+Shift+] selects code between matching parentheses.

Ctrl+Shift+F

Good old Find In Files.

Ctrl+Space, Visual Studio gives the possible completions.

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

See Also: Answer

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.

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

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

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.

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;

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

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+F5 (Start Without Debugging)

CTRL+SHIFT+B (Build Solution)

Ctrl+F10

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

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

F10 : Debug.StepOver

:)

Select word: Ctrl+W

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

Ctrl+Shift+S

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

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.

Ctrl+R+T (Runs the current test)

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

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

  • Ctrl+K, C - to Comment out selection

  • Ctrl+k, U - to Uncomment a selection

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

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

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.

Ctrl+[ (Move to corresponding })

Ctrl+Shift+V (Cycle clipboard)

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

F9: toggle and un-toggle breakpoints!

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.

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.

Alt + B + U - Build the current project.

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.

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

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.

Some handy ones that I use often are:

Ctrl+J -> Forces Intellisence to pop up.

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

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

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

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

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

F7 toggles from design view to code view.

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

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

Alt+F4 ;)

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

Ctrl+Shift+R -> Refactor with Resharper

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!

Insert snippet:

Ctrl+K, Ctrl+S

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

I'm a big fan of Ctrl + D + Q to open quickwatch while debugging.

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

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.

Ctrl+Shift+S // Save

Ctrl+Shift+B // Build

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!

Ctrl+X

This cuts (to clipboard) the current line of code.

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+C with no selection in the line: copies the whole line

  • Ctrl+X with no selection - cuts the whole line

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

Helped me fix indentation and remove unneeded spaces quickly

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

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

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.

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.

Refresh javascript intellisense and code coloring.


ctrl+shift+J

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

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.

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.

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

  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

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:

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

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:

  • 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

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

Related