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.
I like Ctrl+M, Ctrl+M. To expand/collapse the current code block.
Stock Visual Studio? F12 - Edit.GoToDefinition.
Having DevExpress' Refactor! installed means that Ctrl-` is my all-time fave, though ;)
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.
Expand Smart Tag (Resolve Menu): Ctrl + . (period)
Expands the tag that shows when you do things like rename an identifier.
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 + - 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.
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.
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.
Ctrl+R+T (Runs the current test)
Ctrl+R+A (Runs all tests in the project)
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.
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+F5 (Start Without Debugging)
CTRL+SHIFT+B (Build Solution)
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.
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
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+K then Ctrl+H to add a line of code to the built in task/todo list
(Ctrl+Alt+K). Very handy!
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)
If 'Favorite' is measured by how often I use it, then:
F10 : Debug.StepOver
:)
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+[ (Move to corresponding })
Ctrl+Shift+V (Cycle clipboard)
There are some great tips and trips and shortcuts on Sara Ford's blog.
By far the most useful (after Ctrl+Shift+B) are:
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.
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 ;)
Ctrl+- and Ctrl+Shift+-. But if you are a keyboard lover then go for Resharper
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+F10
run to cursor when debugging. Looked for this for ages before I found the keyboard shortcut...
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.
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...
The combination Ctrl+F3 and Ctrl+Shift+F3 for finding selected and previous selected item works very well for me.
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:
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.
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.
"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.
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:
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.
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
.
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.
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.
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.
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+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!
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.
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
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..
F7 to build and then F8 to go to the errors and warnings one by one.
Hmmm, nobody said F1 for help.
Could it be that Google is faster and better for getting at the information that you need.
Some handy ones that I use often are:
Ctrl+J -> Forces Intellisence to pop up.
Ctrl+Alt+L -> Show the Solution Explorer.
Select word: Ctrl+W
I can't live without that shortcut. Used over 100+ (or 200+) a day.
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.
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:
Alt+F4 ;)
But on a more serious note, Ctrl+Space is probably hit a lot from me, in my limited usage of VS.
I've mapped File.Close to CTRL+SHIFT+W. That and CTRL+TAB mean you can close exactly whichever files you want.
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!
Here are my favourite debugging keyboard shortcuts:
Insert snippet:
Ctrl+K, Ctrl+S
I use if often for try..catch and #region
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
Ctrl-Shift-Space shows the syntax/overloads for the current function you are typing parameters for.
Paste in loop Ctrl + Shift + V
Expand Collapse current block - Ctrl + M + M
Code Snippet - for creating property type prop and press tab.
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.
By usage, the pair:
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.
It's simple, but
Ctrl + L
deletes the entire line. Great for fast code editing.
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!
The combination Ctrl+u and Ctrl+Shift+u for converting a block of characters to all upper/lower case.
Ctrl + K + C - set current selected code to be comments Ctrl + K + U - set current selected comments to be code
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.
Open a newline above Ctrl + Enter
Open a newline below Ctrl + Shift + Enter
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.
Haven't seen this one ...
Ctrl + Up
Ctrl + Down
Scrolls the window without moving the cursor.
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.
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.
i not run with Microsoft way so i use my own shortcut. i customize then i feel my development better and easier
Surround With
CTRL + k , s
great when you want to wrap some text in a tag