Hidden Features of Visual Studio (2005-2010)?
Asked Answered
S

100

182

Visual Studio is such a massively big product that even after years of working with it I sometimes stumble upon a new/better way to do things or things I didn't even know were possible.

For instance-

  • Crtl + R, Ctrl + W to show white spaces. Essential for editing Python build scripts.

  • Under "HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0\Text Editor" Create a String called Guides with the value "RGB(255,0,0), 80" to have a red line at column 80 in the text editor.

What other hidden features have you stumbled upon?

Skilling answered 19/9, 2008 at 8:11 Comment(1)
thanks. actually, I stumbled at "show white spaces" by accident, and wanted to get rid of it. thanks a lot!T
S
123

Make a selection with ALT pressed - selects a square of text instead of whole lines.

Skilling answered 19/9, 2008 at 8:11 Comment(11)
Not sure about the difference but I've always used Ctrl+Alt.Madwort
Ctrl-Alt will select whole words. Alt will change the size of the selection area by one character at a time.Proglottis
It looks as if they "fixed" (or broke) the paste of a selected block like this, however. Used to be, you could paste code on top of other code, now it appears to always paste new lines. I used the crap out of this for building CTORS, or = operators with lots of members to assign.Pineapple
Oh my gosh!! I've wanted this forever, but I didn't think VS.Net would ever have it! I remember it from the old WordStar days, believe it or not!Bunyan
at first I thought "when will I ever use this", and now I use it almost every day for copy pasting some code to an email, messenger window, stackoverflow, ..Abductor
This works in MS Word and OO Writer as well. I've used it a lot.Peyter
This (called "block select") also works with the keyboard- hold alt+shift then use the arrow keys.Halsey
In addition, if you select an empty horizontal column this way, anything you type will get duplicated on every line, behaving like a huge cursor :)Fireproofing
Your mileage may vary if you copy-paste the rectangular selection.Brownfield
I saw this being sold as a feature for VS 2010, but I just tried it in VS 2008 and it worked. I'm flabbergasted. this is amazingly usefull!Yezd
alt + W: comment; alt + e: uncommentSamaria
C
95

Tracepoints!

Put a breakpoint on a line of code. Bring up the Breakpoints Window and right click on the new breakpoint. Select 'When Hit...'. By ticking the 'Print a message' check box Visual Studio will print out a message to the Debug Output every time the line of code is executed, rather than (or as well as) breaking on it. You can also get it to execute a macro as it passes the line.

Cavil answered 19/9, 2008 at 8:11 Comment(2)
I know I'm late to the game, but that's a great feature I never knew about!Shiff
For extra points you can make a local variable asignment in the when hit button. { localVariable = 1.0f } or increase values by { staticVariable += 0.1f }Dunghill
R
91

You can drag code to the ToolBox. Try it!

Ringe answered 19/9, 2008 at 8:11 Comment(4)
doesn't seem to be much use over snippets thoughIntroject
Dear God...it's a whole new level of copy-and-paste. Copy-and-paste-paste-paste. I know a lot of programmers who I hope never find out that you can do this.Dereism
It would be cool if you could tell it to eval the code when you clicked the button, like a bookmarklet.Trod
oh no. What is this bastardize function doing!Pitchfork
M
79

Click an identifier (class name, variable, etc) then hit F12 for "Go To Definition". I'm always amazed how many people I watch code use the slower right-click -> "Go To Definition" method.

EDIT: Then you can use Ctrl+- to jump back to where you were.

Madwort answered 19/9, 2008 at 8:11 Comment(8)
And don't forget Ctrl+Shift+- [control shift minus] to jump forward!Haldeman
And Shift F12 for Find all referencesGoulder
If you use code that has Interfaces, Go To Definition doesn't always work but if you have ReSharper Ctrl+F12 works! (goes to Implementation)Woodsman
You can also use ALT+left arrow to go back to where you wereHalsey
With VB key settings, Shift-F2 also does a Go To Definition.Dereism
Resharper does this even nicer - when you hold down ctrl and click on a method call you ski to method declarationRacemic
Might as well right-click-G if you're going the mouse route in the first place.Spank
+ 1 for the "CTRL -" shortcutIda
L
57

CTRL+SHIFT+V will cycle through your clipboard, Visual Studio keeps a history of copies.

Legged answered 19/9, 2008 at 8:11 Comment(1)
this can be found in edit.cycleclipboardring in keyboard mappings (in visual c++ this is Ctrl-Shift-Insert, not Ctrl-Shift-V)Tubulure
B
52

Sara Ford covers lots of lovely tips: http://blogs.msdn.com/saraford/archive/tags/Visual+Studio+2008+Tip+of+the+Day/default.aspx

But some of my favourites are Code Snippets, Ctrl + . to add a using <Namespace> or generate a method stub. I can't live without that.

Check out a great list in the Visual Studio 2008 C# Keybinding poster: http://www.microsoft.com/downloadS/details.aspx?familyid=E5F902A8-5BB5-4CC6-907E-472809749973&displaylang=en

Botti answered 19/9, 2008 at 8:11 Comment(8)
Sara Ford is the goddess of Visual Studio. I couldn't recommend her enough.Polyzoan
Totally agree which I why I share her work. I'm really loving her current series which covers debuggingKatrinakatrine
Sad that she quit doing the tip of the day, though it's been so long since she worked with the innards of VS that it's completely understandable that she needed to move on...Merrileemerrili
Thank you for mentioning CTRL+. I was searching for this one exactly.Speaks
I was always using CTRL+ALT+F10. Didn't know CTRL+. does the same thing - thanks. Much more comfortable.Hiccup
@Noam- I used to use CTRL + ALT + F10, only discovered CNTRL+. by reading the book Pro ASP.NET MVC. Much better with CNTRL+.Autostability
Ctrl + K + M is faster than Ctrl + . if you are sure that you wanted to generate a method. One of my favorite is Ctrl + K + S for surrounding code with various code blocks like if, try, region etc.Spaceless
The 101 VS Tips in 55 Minutes is currently hosted here: saraford.net/2010/06/17/…Ballroom
C
49
CTRL-K, CTRL-D

Reformat Document!
This is under the VB keybindings, not sure about C#

Corked answered 19/9, 2008 at 8:11 Comment(2)
yes, works under C#, Web Designer, XML editor, CSS editor, XSD editor, JavaScript (to an extent). Most of the supported file typesKatrinakatrine
Ctrl+K, Ctrl+F also formats whatever text you have selected (in C#, not sure about others).Komsomolsk
I
43

How many times do you debug an array in a quickwatch or a watch window and only have visual studio show you the first element? Add ",N" to the end of the definition to make studio show you the next N items as well. IE "this->m_myArray" becomes "this->m_array,5".

Intermixture answered 19/9, 2008 at 8:11 Comment(0)
S
41

Incremental search: While having a source document open hit (CTRL + I) and type the word you are searching for you can hit (CTRL + I) again to see words matching your input.

Shipping answered 19/9, 2008 at 8:11 Comment(3)
It's called ">i<ncremental search".Inconstant
As opposed to >ex<cremental search, which is what Firefox implements.Brownfield
Coming from the Emacs world, this the first feature I looked for. :)Onitaonlooker
A
37

You can use the following codes in the watch window.

@err - display last error
@err,hr - display last error as an HRESULT
@exception - display current exception
Anderson answered 19/9, 2008 at 8:11 Comment(0)
R
35
  • Ctrl-K, Ctrl-C to comment a block of text with // at the start
  • Ctrl-K, Ctrl-U to uncomment a block of text with // at the start

Can't live without it! :)

Ravage answered 19/9, 2008 at 8:11 Comment(10)
Also true in VB.NET, except with ' rather than //Drusilladrusus
Also true in SQL Server Management Studio, except using the SQL comment escape sequence of '--'Ravage
I always wished you could toggle comments? Why would you want to "double comment" something? Surely pressing it again should un-comment...Aileen
Sometimes you want to comment the entire function, and some lines inside are already commented (i.e. they are proper comments). In such cases it's not obvious what to do if you have a toggle, so it's generally better to make the decision explicit.Declination
I wish there was an easy way to wrap a block of text in /* ... */ rather than prepending every line with //. I've started doing this by hand rather than lazily using Ctrl-E, Ctrl-C. Why? Because if you comment out a block of code, which someone else modifies, you get conflicts when you try to merge them (when using a DVCS). If you wrap blocks with C style comments however, then the commented out code gets modified automatically. Also in your revision control, you only see the first and last line of the block as modified, not every line of the block, which makes changesets easier to review.Hallock
Note that if you start at the beginning of text rather then beginning of line you will get the /* */ instead of //. This is by the way my most used featureTubulure
for such a useful feature, it should be simpler than something tha requires 2 hands.Yezd
@DaveDev: You use 1 hand when you are programming?Tubulure
@Michael, sometimes when I'm lonely. But otherwise I might be selecting a block of code with the mouse, and then I have to move my hand to the keyboard, and then back again to the mouse. It's not much of an overhead, but if you're doing it a lot it can get tediousYezd
@DaveDev: lol :) right, I usually mark the code with shift-up/down.. So personally not that much hassle. But if you are selecting it with the mouse, it should be one click. Although, you can map it yourself to a one-hand-..click (How about, Ctrl -C[omment] ;))Tubulure
C
25

Stopping the debugger from stepping into trivial functions.

When you’re stepping through code in the debugger, you can spend a lot of time stepping in and out of functions you’re not particularly interested in, with names such as GetID(), or std::vector<>(), to pick a C++ example. You can use the registry to make the debugger ignore these.

For Visual Studio 2005, you have to go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio \8.0\NativeDE\StepOver and add string values containing regular expressions for each function or set of functions you wish to exclude; e.g.

std::vector.*::.*
TextBox::GetID

You can also override these for individual exceptions. For instance, suppose you did want to step into the vector class’s destructor:

std::vector.*::\~.*=StepInto

You can find details for other versions of Visual Studio at http://blogs.msdn.com/andypennell/archive/2004/02/06/69004.aspx

Cavil answered 19/9, 2008 at 8:11 Comment(1)
Wow, this is awesome. I had no idea this was possible.Bellbottoms
J
23

TAB key feature.

  1. If you know snippet key name, write and click double Tab. for example: Write

    foreach

and then click tab key twice to

foreach (object var in collection_to_loop)
{

}

2. If you write any event, write here

        Button btn = new Button();
        btn.Click +=         

and then click tab key twice to

private void Form1_Load(object sender, EventArgs e)
{
        Button btn = new Button();
        btn.Click += new EventHandler(btn_Click);     
}    
void btn_Click(object sender, EventArgs e)
{
        throw new Exception("The method or operation is not implemented.");
}

btn_Click function write automatically

  1. in XAML Editor, Write any event. for example:

MouseLeftButtonDown then click tab
MouseLeftButtonDown="" then click tab again MouseLeftButtonDown="Button_MouseLeftButtonDown" in the code section Button_MouseLeftButtonDown method created.

Jaddo answered 19/9, 2008 at 8:11 Comment(0)
A
23

Ctrl-F10: run to cursor during debugging. Took me ages to find this, and I use it all the time;

Ctrl-E, Ctrl-D: apply standard formatting (which you can define).

Altorilievo answered 19/9, 2008 at 8:11 Comment(1)
Ctrl+Shift+F10 to skip all code and run to the cursor. Nifty when trying to test specific lines of code.Lytta
Y
21

T4 (Text Template Transformation Toolkit). T4 is a code generator built right into Visual Studio

Yorke answered 19/9, 2008 at 8:11 Comment(1)
Note: Not the Express Editions. (Still a great tip though.)Bellbottoms
T
21

Sara Ford has this market cornered.

http://blogs.msdn.com/saraford/default.aspx

More Visual Studio tips and tricks than you can shake a stick at.

Some others:

  • The Visual Studio 2005 and 2008 3-month trial editions are fully-functional, and can be used indefinitely (forever) by setting the system clock back prior to opening VS. Then, when VS is opened, set the system clock forward again so your datetimes aren't screwed up.
  • But that's really piracy and I can't recommend it, especially when anybody with a .edu address can get a fully-functional Pro version of VS2008 through Microsoft Dreamspark.
  • You can use Visual Studio to open 3rd-party executables, and browse embedded resources (dialogs, string tables, images, etc) stored within.
  • Debugging visualizers are not exactly a "hidden" feature but they are somewhat neglected, and super-useful, since in addition to using the provided visualizers you can roll your own for specific data sets.
  • Debugger's "Set Instruction Pointer" or "Set Next Statement" command.
  • Conditional breakpoints (as KiwiBastard noted).
  • You can use Quickwatch etc. to evaluate not only the value of a variable, but runtime expressions around that variable.
Thrombus answered 19/9, 2008 at 8:11 Comment(2)
If it's really piracy (which I agree with you about), then why would you even mention it?Dereism
Kyralessa, because some people probably don't care. However, with the Express editions being free I doubt there is an actual reason nowadays to use a pirated VS version.Lamebrain
P
17

Custom IntelliSense dropdown height, for example displaying 50 items instead of the default which is IMO ridiculously small (8).

(To do that, just resize the dropdown next time you see it, and Visual Studio will remember the size you selected next time it opens a dropdown.)

Phillipp answered 19/9, 2008 at 8:11 Comment(2)
You can't resize it anymore in VS2010, it bug me to no end.Stepha
in Vs2008 I'm able to change the width but not the height .Statement
G
16

Discovered today:

Ctrl + .

Brings up the context menu for refactoring (then one that's accessible via the underlined last letter of a class/method/property you've just renamed - mouse over for menu or "Ctrl" + ".")

Gasworks answered 19/9, 2008 at 8:11 Comment(2)
Alt+Shift+F10 does this as well (using C# keybindings)Oldie
Much better than trying to hunt the tiny mouse click target in this situationDefence
S
14

A lot of people don't know or use the debugger to it's fullest - I.E. just use it to stop code, but right click on the red circle and there are a lot more options such as break on condition, run code on break.

Also you can change variable values at runtime using the debugger which is a great feature - saves rerunning code to fix a silly logic error etc.

Slaby answered 19/9, 2008 at 8:11 Comment(0)
L
13

Line transpose, Shift-Alt-T
Swaps two line (current and next) and moves cursor to the next line. I'm lovin it. I've even written a macro which changed again position by one line, executed line transpose and changed line position again so it all looking like I swapping current line with previous (Reverse line transpose).

Word transpose, Shift-Ctrl-T

Liken answered 19/9, 2008 at 8:11 Comment(3)
This makes the line move down the page, how do you make a line move UP the page?Ives
GordonG, I've written following macro: Sub ReverseLineTranspose() DTE.ActiveDocument.Selection.LineUp DTE.ExecuteCommand ("Edit.LineTranspose") DTE.ActiveDocument.Selection.LineUp End SubLiken
Could do with it here as it turns out :)Goulder
L
11

Document Outline in the FormsDesigner (CTRL + ALT + T)

Fast control renaming, ordering and more!

Limiter answered 19/9, 2008 at 8:11 Comment(1)
I can't believe I didn't know about this. My life is changed.Vday
P
11

To auto-sync current file with Solution Explorer. So don't have to look where the file lives in the project structure

Tools -> Options -> Projects and Solutions -> "Track Active Item in Solution Explorer"

Edit: If this gets too annoying for you then you can use Dan Vanderboom's macro to invoke this feature on demand through a keystroke.

(Note: Taken from the comment below by Jerry).

Poliomyelitis answered 19/9, 2008 at 8:11 Comment(4)
this gets annoying after a while. i wish there were a keyboard shortcut to do this on demand.Pipsissewa
Here's a post on how to track on demand. dvanderboom.wordpress.com/2008/03/21/…Shiff
If you have lots of files open, it can kill VS (without warning) if you do things like 'Close all but this' (from PowerCommands, I think).Goulder
Resharper makes the need for this redundant as you can do Shift+Alt+L to jump directly to the current file in the Solution Explorer; or Ctrl+Shift+N to keyword search for any file in the Solution.Mcmahan
P
11

When developing C++, Ctrl-F7 compiles the current file only.

Procrastinate answered 19/9, 2008 at 8:11 Comment(0)
C
9

Ctrl-Minus, Ctrl-Plus, navigates back and forward where you've been recently (only open files, though).

Cornelius answered 19/9, 2008 at 8:11 Comment(2)
Yep, LOVE these- use them everyday.Norwich
Very useful if you hit F+12 to go to a definition and then want to go back to where you were.Ravage
A
9

I'm not sure if it's "hidden", but not many people know about it -- pseudoregisters. Comes very handy when debugging, I've @ERR, hr in my watch window all the time.

Athwartships answered 19/9, 2008 at 8:11 Comment(3)
I've heard @xxx is being phased out in favor of $xxx. FWIW, WinDbg also uses $xxx form.Inconstant
Can't you just do "hr,hr" in a watch window? I've used that all the way back in VC6...Pineapple
Excellent. As the linked article suggests, setting conditional breakpoints on @TIB will drastically simplify the debugging of multithreaded apps.Bellbottoms
A
9

Here's something I learned (for C#):

You can move the cursor to the opening curly brace from the closing curly brace by pressing Control + ].

I learned this on an SO topic that's a dupe of this one:

“Hidden Secrets” of the Visual Studio .NET debugger?

Assemblyman answered 31/8, 2009 at 4:46 Comment(0)
P
9

I don't use it often, but I do love:

ctrl-alt + mouse select

To select in a rectangular block, to 'block' boundaries.

As noted in comments,

alt + mouse select

Does just a plain rectangular block.

Prodrome answered 31/8, 2009 at 4:48 Comment(6)
A downvote is amusing, given that this is a valid action in VS :) Good luck to you though, mysterious hater.Prodrome
Maybe it's a bit early, but reading this made me want to try it on Firefox. Turns out, ctrl-alt-shift allows you to use the mouse to drag the entire document across the screen, similar to how a PDF document works.Landonlandor
How does it differ from alt + mouse select?Tilley
Guffa: It goes to block-endings only. alt-select lets you choose any area containing anything. They are different.Prodrome
Though I do think it can just be 'ctrl-alt', not 'shift' as well.Prodrome
It's actually just Shift+Alt in Firefox.Tinishatinker
P
8

Middle Mouse Button Click on the editor tab closes the tab.

Pincer answered 19/9, 2008 at 8:11 Comment(1)
I use this all the time when I'm coding because I'm looking up code and then closing it (the "X" for closing is rather far).Pincer
E
8

To display any chunk of data as an n-byte "array", use the following syntax in Visual Studio's QuickWatch window:

variable, n

For example, to view a variable named foo as a 256-byte array, enter the following expression in the QuickWatch window:

foo, 256

This is particularly useful when viewing strings that aren't null-terminated or data that's only accessible via a pointer. You can use Visual Studio's Memory window to achieve a similar result, but using the QuickWatch window is often more convenient for a quick check.

Emmerich answered 19/9, 2008 at 8:11 Comment(0)
G
8

CTRL + Shift + U -> Uppercase highlighted section. CTRL + U -> Lowercase the highlighted section Great for getting my SQL Statements looking just right when putting them into string queries.

Also useful for code you've found online where EVERYTHING IS IN CAPS.

Geulincx answered 19/9, 2008 at 8:11 Comment(1)
Too bad they don't have a CamelCase CTRL+Shift option... :) That's probably my #1 refactor I do when I take over a project... LarryPineapple
I
7

Ctrl + Delete deletes the whole word (forward)

Ctrl + Backspace deletes the whole word (backward)

The following is well known but am I wrong saying it hasn't been listed yet ?

Ctrl + Shift + Space inside the parentheses of a method call gives you the parameter info.

Iou answered 19/9, 2008 at 8:11 Comment(0)
D
7

CTRL-D then type ">of " then file name. If the standard toolbar is up crtl-d put you in find combobox and there is now a dropdown with files in your solution that match the start of the filename you typed. Pick one and it will open it. This alternative to the open filedialog is awesome for big solutions with lots of directories.

Denary answered 19/9, 2008 at 8:11 Comment(1)
My Visual Studio has CTRL+/ to get to the find box. But I use this all the time.Legged
D
6

.NET debugger allows you to give objects identifiers, and to refer them via those identifiers later during the session. To do so, you right-click on the variable (or expression) referencing the object in Autos/Locals/Watch window, or in the tooltip, and select "Create Object ID". IDs are sequential integer numbers, starting from 1, and suffixed by "#" - e.g 1# will be the first ID you create.

After the ID is created, if the object is associated with a given ID, it is displayed in parentheses.

You can use 1# to reference the object by ID anywhere you can normally use expressions - in Watch window, in condition of a conditional breakpoint, and so on. It's most handy when you want to set a breakpoint on a method of some particular object only - if you can first track the object creation, or some other place where this particular object is referenced, you just create the ID for it, and then set a new breakpoint with condition such as this==1#.

Declination answered 19/9, 2008 at 8:11 Comment(0)
C
6

Drag-drop text selections to the Watch window while in the debugger.

Claqueur answered 19/9, 2008 at 8:11 Comment(0)
S
5

During debugging, Select an identifier or expressing and drag it to the watch window.
Beats having to write it from scratch :)

Skilling answered 19/9, 2008 at 8:11 Comment(0)
C
5

I accidentally found this one just now. When you are anywhere on a line and press Ctrl + Enter, it will insert a new line above the current line and move the cursor there.

Also, if you press Ctrl + Shift + Enter, it will insert a new line below the current line and move the cursor there (similar to End, Enter)

Chromic answered 19/9, 2008 at 8:11 Comment(0)
A
4

Ever want to look for a function in your current viewed file but there are too many member to browse? Need a filter? Then, the Navigate box is what you need. You activate it by Ctrl-, (comma).

Arabelle answered 19/9, 2008 at 8:11 Comment(0)
S
4

In the watch window, you can view the current exception even if you have no variable to hold it by adding a watch on $exception

Satisfactory answered 19/9, 2008 at 8:11 Comment(0)
R
4
  • Ctrl-K, Ctrl-C to comment a block of text with // at the start
  • Ctrl-K, Ctrl-U to uncomment a block of text with // at the start

Can't live without it! :)

Ravage answered 19/9, 2008 at 8:11 Comment(0)
I
4

Press the F8 key to cycle through search results. (Shift+F8 for reverse direction)

Hit F12 to go to definition of variable.

Shift + alt + arrow keys = Block select!

Ida answered 19/9, 2008 at 8:11 Comment(0)
B
4
  • The memory windows, very useful if you're doing low level stuff.
  • Control + K , Control + F - Format selection - great for quickly making code neat
  • Regions, some love them, some hate them, most don't even know they exist
  • Changing variables in debug windows during execution
  • Tracepoints
  • Conditional break points
  • Hold down Alt and drag for 'rectangular' selection.
  • Control+B for a breakpoint, to break at function
  • Control+I for incremental search, F3 to iterate
Bellicose answered 19/9, 2008 at 8:11 Comment(0)
E
3

Ctrl+Tab - switch between open tabs/windows in Visual Studio 2005 & 2008.

Kind of like Alt+Tab in Windows, brings up a little box just for the currently open VS files.

Here's a sample screenshot:

alt text http://lh3.ggpht.com/_FWrysR9YI18/TFOGxnX9ShI/AAAAAAAAAQI/a-ByCRMmrpw/ctrltab.gif

Epictetus answered 19/9, 2008 at 8:11 Comment(2)
Use arrow keys to navigate between those tabs and windows (while tab is pressed)Tubulure
@Default you mean : while ctrl pressedHalftrack
T
3

Close all documents other than the one your on by right clicking the doc's tab and selecting "Close All But This." You can do this in many other IDEs and browsers as well. Not a big feature but I find that I use it 10+ times a day. This feature was hidden from me for many years. I should map it to a keyboard shortcut :p

Thadthaddaus answered 19/9, 2008 at 8:11 Comment(0)
P
3

Pseudovariables in the debugger: http://msdn.microsoft.com/en-us/library/ms164891.aspx

$exception: avoids the need to give your exceptions names (and cause variable not referenced warnings).

$user: tells you which user is running the application...sometimes useful when trying to diagnose permission issues.

Phthalocyanine answered 19/9, 2008 at 8:11 Comment(0)
N
3

I'm surprised no one has mentioned this yet. I find the ability record and play back a series of actions very, very helpful sometimes. Like if I'm applying some repetitive action to a few lines in a text file.

For example

Ctrl+Shift+R (start recording macro)

perform a series of keystrokes

Ctrl+Shift+R (stop recording macro)

later....

Ctrl+Shift+P (play back keystrokes)

This approach is ideal for a short, one time manipulations. If it's something more involved or needed more than once, I'll write a script.

Nucleonics answered 19/9, 2008 at 8:11 Comment(3)
I'd like to use your tip to delete a line quickly! Currently VS just provide hotkey to cut a line. Your tips is a quick way to add a temporary shortcut (i.e. Ctrl-Shift-P).Arabelle
I also use this tips to quickly open the Pending Changes pane.Arabelle
I use this all the time when cleaning out or formatting files. I use this and sometimes regexPitchfork
S
3

View, Other Windows, Object Test Bench

The object test bench can be used to execute code at design-time.

You can right-click on a type in Class View, click Create Instance, and select a constructor. You can then supply values for its parameters, if any, and the instance will show up in the Object Test Bench.

You can also call static methods by right-clicking a type and clicking Invoke Static Method.

In the Object Test Bench, you can right-click on an object to call methods, and you can hover over it and see its structure (like you can when debugging). You can also assign to and interact with these variables in the Immediate window, also at design time.

This feature can be useful when writing a library. Please note that to use this, your solution must be compile first.

Sixteenmo answered 19/9, 2008 at 8:11 Comment(0)
S
3

You can drag down the little gray box above the vertical scrollbar to split the window into two views of the same file, which can be scrolled independently - great if you're comparing two parts of the same file.

Sixteenmo answered 19/9, 2008 at 8:11 Comment(2)
This is awesome for web stuff, such as keeping css/javascript in the top portion and the HTML in the bottom. Also for rewriting a long method, you can keep the "old" version in one area for reference while you write the new one in the other pane.Tinishatinker
i'd just use windiff or the likesPitchfork
B
3

There is an article about this. It seems to be a lengthy collection.

Barleycorn answered 19/9, 2008 at 8:11 Comment(0)
E
3

Shift+Alt+F10 brings up the built in refactoring menu. Great for adding method stubs from interfaces, and adding Using statements automatically for specific classes.

Establishment answered 19/9, 2008 at 8:11 Comment(1)
An easier way to do this is Ctrl-. (period)Saretta
B
3

Dynamic XSLT Intellisense

A very little known fact is that Visual Studio 2008 does support real XSLT intellisense - not a static XSLT schema-based one, but real dynamic intellisense enabling autocompletion of template names, modes, parameter/variable names, attribute set names, namespace prefixes etc.

For all versions of VS I like

Ctrl + Shift + V

for copying data in clipboard cycle.

Blakeley answered 31/8, 2009 at 4:45 Comment(1)
Cool, didn't know control-shift-v.Prodrome
P
3

I don't know how 'hidden' this is, but some newew people may not know about coniditonal breakpoints.

Set a breakpoint, then right click it, and choose Condition, then enter an expression like:

(b == 0)

And it will only fire when that is true. Very useful when trying to debug a certain stage of a loop.

Prodrome answered 31/8, 2009 at 4:55 Comment(1)
I think the general approach in these threads is to put one answer per comment, so people can rank them individually. I'm not getting any more points today via upvotes anyway, so it doesn't bother me either way :)Prodrome
V
3

The existence of the Resharper add-in. It makes working with Visual Stupidio less of a pain :)

It's not really a hidden feature, but worth mention nonetheless as it comes with tons of these tricks and hotkeys.

Vitia answered 31/8, 2009 at 5:31 Comment(0)
H
2

The features I like the most are

  1. Bookmarks feature. You can add/remove bookmarks in code(kinda like breakpoints), and you can navigate directly between them by using next/previous bookmark. Very useful if you are making changes in two places at once, and want to swap between the two frequently.
  2. The comment/uncomment feature. Ctrl+E , Ctrl+C/U for C# settings.
  3. The increase/decrease indent of a line. (Only available for VC by default. To assign for C#, go to tools -> Options -> General -> Keyboard and change the Edit.IncreaseLineIndent/Edit.DecreaseLineIndent for TextEditor)

PS: I want to know how to navigate to the members drop down list (just below the tabs list) by the keyboard.

Huckleberry answered 19/9, 2008 at 8:11 Comment(2)
+1 for the bookmarks feature (even though I don't think it is very hidden :])Tubulure
@michael : I haven't actually seen anybody else use it, and even I forget about it at times.Huckleberry
L
2

One that I only just discovered. When dealing with COM it's possible to lookup a brief message from the cryptic hexadecimal error number using a tool called errlook.exe.

The useful tool is located in your VS\Common7\Tools directory.

Lefthanded answered 19/9, 2008 at 8:11 Comment(1)
You can run it with Tools -> Error LookupStripling
P
2

I see that lot of us are posting shortcuts. I have printed this poster, it's very helpful to learn those shortcuts - nowadays I look very rarely at the poster 'cause I've learned most of them :)

Link for VS posters:

http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=c15d210d-a926-46a8-a586-31f8a2e576fe

My favourites are Refactoring ones (CTRL-R + Something)

Pals answered 19/9, 2008 at 8:11 Comment(0)
M
2

View, Code Definition Window.

The Code Definition Window shows the definition of the currently selected identifier (If it's in your solution, it'll show your sourced; otherwise, it'll extract metadata, like right-click, Go To Definition)

Maurey answered 19/9, 2008 at 8:11 Comment(0)
S
2

Ctrl+Shift+L deletes the current line (without cutting it to the clipboard)

Sixteenmo answered 19/9, 2008 at 8:11 Comment(0)
W
2

Ctrl-T swaps the last two letters. For example, "swithc" -> "switch".

Wreak answered 19/9, 2008 at 8:11 Comment(2)
@Shoosh, it's quicker than prinft m_variablena "woops!", backspace, backspace, backspace, backspace, backspace, backspace etc...Goulder
Actually i just tried this in VS 2008 and it seems to swap the two letters that are on either side of the cursor, so if you have switch and the cursor is between the w and i Ctrl-T makes it siwtch.Errand
I
2

Ctrl-M + Ctrl-L Toggle Collapse All - Expand All

Inman answered 19/9, 2008 at 8:11 Comment(0)
U
2

Ctrl+L deletes the current selected line. This is an awesome time saver (if used responsibly of course!!!)

Urbanite answered 19/9, 2008 at 8:11 Comment(3)
Unfortunately it cuts the current line, pwning your clipboard. I really wish there was a command that just deleted the current line...Disband
And Ctrl + X while nothing is selected cuts the current line. Same for copy. No need to remember any new letters of the alphabet then.Vacuity
Shift+Ctrl+L deletes the current line without putting it in the clipboard. (From SLaks's answer.)Bellbottoms
P
2

Here is the Macro source for my aspx/aspx.cs flipper. It works in 2005, but it may have issues in 08.. I'm not sure... This was taken from my other cpp/h flipper, so there might be some clean up needed to make it the best it could be. I'm not paid to write Macros, so I have to blast though them as quickly as possible when I need one.

    Sub OpenASPOrCS()
    'DESCRIPTION: Open .aspx file if in .cs file, open .cs file if in .aspx file
    On Error Resume Next

    ' Get current doc path
    Dim FullName
    FullName = LCase(ActiveDocument.FullName)
    If FullName = "" Then
        MsgBox("Error, not a .cs or asp file!")
        Exit Sub
    End If

    ' Get current doc name
    Dim DocName
    DocName = ActiveDocument.Name

    Dim IsCSFile
    IsCSFile = False
    Dim fn
    Dim dn
    If (Right(FullName, 3) = ".cs") Then
        fn = Left(FullName, Len(FullName) - 3)
        dn = Left(DocName, Len(DocName) - 3)
        IsCSFile = True
    ElseIf ((Right(FullName, 5) = ".aspx") Or (Right(FullName, 5) = ".ascx")) Then
        fn = FullName + ".cs"
        dn = DocName + ".cs"
    Else
        MsgBox("Error, not a .cs, or an asp file!")
        Exit Sub
    End If

    Dim doc As EnvDTE.Documents

    DTE.ItemOperations.OpenFile(fn)
    doc.DTE.ItemOperations.OpenFile(fn)

    If Err.Number = 0 Then
        Exit Sub
    End If

    ' First check to see if the file is already open and activate it
    For Each doc In DTE.Documents()
        If doc.Name = dn Then
            doc.Active = True
            Exit Sub
        End If
    Next

End Sub
Pineapple answered 19/9, 2008 at 8:11 Comment(0)
C
2

Copy-paste from a Watch window of an object's expanded properties in the debugger into Excel will perserve the tabular format and persist the data after the debug session is over.

Claqueur answered 19/9, 2008 at 8:11 Comment(0)
C
2

I think the ability to right click on a Stored Procedure in Server Explorer and debug..

Crissman answered 19/9, 2008 at 8:11 Comment(0)
K
2

I always map control + alt + f4 to documents.CloseAllWindows in options>environment>keyboard.

Is somewhat more intuitive than using the mouse.

Keirakeiser answered 19/9, 2008 at 8:11 Comment(1)
Got this at ctrl+shit+alt+q. But it's quite fast through alt+w+w too.Calorie
B
2

The Debugger :-) Beats Notepad by miles.

Bonham answered 19/9, 2008 at 8:11 Comment(2)
VS Debugger is Notepad when compared to windbg :)Inconstant
True, but if the VS Debugger is Notepad, then windbg is vi or emacs :-)Bonham
F
2

The most important feature I can't live without is Visual Studio 2008. :P

Falla answered 19/9, 2008 at 8:11 Comment(0)
S
2

There is this blog on MSDN thats got some nice tips and tricks

http://blogs.msdn.com/saraford/archive/tags/Visual+Studio+2008+Tip+of+the+Day/default.aspx

Synectics answered 31/8, 2009 at 4:59 Comment(0)
S
1

Set next statement by right-clicking code view during debugging or just dragging the yellow arrow around.

This is really useful to debug again a part of the code you have recently stepped over, or maybe change the content of some variable and trying to execute a set of statements again.

Siusiubhan answered 19/9, 2008 at 8:11 Comment(0)
A
1

Navigating around the references of a symbol in VS 2010: 1. Place your cursor at the symbol to high light all references 2. Ctrl - Alt - Up/Down to navigate backward/toward reference.

^_^

Arabelle answered 19/9, 2008 at 8:11 Comment(0)
B
1

I'm sure everyone knows this, it's not just VS, you can do it almost everywhere. If you press Ctrl + left arrow/right arrow you will go to the next/last word word. You can also Ctrl + Shift + left/right arrow to select whole words at a time.

Basra answered 19/9, 2008 at 8:11 Comment(0)
F
1

Ctrl + Shift + F brings up "search solution" dialog and lists all the results in a nice navigable way, rather than visiting each result. Not only it's easier to use, it's also useful because it doesn't tamper with your search scope defaults you use with regular search.

Fireproofing answered 19/9, 2008 at 8:11 Comment(0)
C
1

How about Ctrl + C to copy the current line to the clipboard without doing any range selection. This is sooooo... simple and useful.

Cay answered 19/9, 2008 at 8:11 Comment(1)
@Wijeratna: Do you know how to quickly delete/move up/move down a line?Arabelle
M
1

In addition to all others said like:

  • Ctrl + K + D
  • Ctrl + K + U
  • Ctrl + M + L
  • Ctrl + M + O

Selecting when you hold "Alt".
Hiting F12 on the instead of right click and choose "Go To Definition".

  • Ctrl + K + C for comment.
  • Ctrl + K + U for uncommenting.

Today if found something new:
In WebFroms in Design mode, go to Tools menu and choose "Generate Local Resources". It's really handy for making multilingual web applications.

Malleus answered 19/9, 2008 at 8:11 Comment(2)
Not sure what you mean by Ctrl-K-D?Arabelle
@Nam : When you copy some markup form some where else and past in your code , You lose indentation and some more thing , By Hitting Ctr +K+ D it reorganize againMalleus
D
1
  • Vertical split of the window using "New Window" and "New Vertical Tab Group" combination.

There is only horizontal split in VS by default, but trick with window duplication allows to use vertical split too.

  • Vertical selection is good (it accessible with keyboard too: Alt+Shift+[Ctrl]+Arrows). But sometimes I need to use Vertical Copy/Cut and Paste. VS is smart enough to handle this correctly.

  • There are also very useful features: Go Next/Prev Scope (Alt+Down/Up), Go to Implementation (Alt+G), but they are a part of the Visual Assist X plug-in.

Drillstock answered 19/9, 2008 at 8:11 Comment(0)
K
1

Mouse Left Click resets your cursor to the position your pointer is currently hovering. Very useful for navigating through Visual Studio.

Keirakeiser answered 19/9, 2008 at 8:11 Comment(0)
D
1

I don't know how unknown most people consider them to be, but I don't think that a lot of people use snippets.

I discovered them a while back and then found that they were customizable by editing the xml in the Visual Studio Program Files directory. They make it super easy to add a lot of code quickly.

Also, to save time when using snippets make sure you hit tab twice and not try to do everything through the right click menu.

Didactics answered 19/9, 2008 at 8:11 Comment(2)
You can also put them in MyDocs\Visual Studio 200?\Code SnippetsSixteenmo
You can see some snippets here: #15611Sixteenmo
I
1

I wanted to talk about comment (Ctrl + k, Ctrl + c) and uncomment (Ctrl + k, Ctrl + u) shortcuts but a Bratt (:p) already mentioned them.

How about the Ctrl + k, Ctrl + d shortcut, very convenient to format markup (ASP.NET, HTML) and JavaScript code!

Ivanivana answered 19/9, 2008 at 8:11 Comment(0)
Q
1

CTRL-G for jumping to a specific line number. Saves a few seconds when you've got a line number in a large code file.

Quarterdeck answered 19/9, 2008 at 8:11 Comment(1)
@sunglim - You're right! I haven't used notepad in years, though.Quarterdeck
P
1

Reference tag of Visual Studio 2008 for JavaScript IntelliSense is a brand new hidden feature. Especially jQuery IntelliSense is a devastating!

Piccolo answered 19/9, 2008 at 8:11 Comment(0)
P
1

Re: Stopping the debugger from stepping into trivial functions.

In C#, you can also add an attribute [DebuggerStepThrough] (using System.Diagnostics) to a method. This causes the debugger to, ironically, not step through the method.

Plectrum answered 19/9, 2008 at 8:11 Comment(0)
B
1

The Open button in the File Open dialog has a little down arrrow next to it. Click that and you get the "Open With" option which includes the Binary Editor. As a systems-type guy, I find it quite valuable, but most of my colleagues hadn't known about it until I showed them.

Bilodeau answered 19/9, 2008 at 8:11 Comment(0)
S
1

Enable Intellisense in Skin Files

  1. Go to Tools->Options menu.
  2. Pick Text Editor -> File Extesion fom a tree at the left part of Options dialog.
  3. Type skin in Extesion text box.
  4. Select User Control Editor from Editor dropdown.
  5. Click Add and then Ok to close dialog and re-open your skin files.
Susurrus answered 19/9, 2008 at 8:11 Comment(0)
P
1

My best feature is one I had to make myself.. It's a cpp/h flipper. If you are looking at the .h file, and hit this macro, (or its keyboard shortcut), it will open the cpp file, and vice-versa.

I can provide the source if anyone wants it.

Pineapple answered 19/9, 2008 at 8:11 Comment(2)
I would love this for flipping between .aspx and .aspx.cs files (likewise for .ascx and .ascx.cs)Defence
Rich, I just wrote one for myself to do this for aspx and .cs... I'll post the code.Pineapple
V
1

Not exactly a hidden feature, but one thing I've done is add a "Start Without Debugging" button next to my "Start With Debugging" button. Just click the down arrow at the right end of the toolbar. Then select "Add or Remove buttons". Then Customize. In the commands tab select the Debug category. Find the Start Without Debugging command and drag it to where you want it on the toolbar.

Valleau answered 19/9, 2008 at 8:11 Comment(1)
CTRL-F5 is the shortcut for this, with the default settings. Great way to run a faster build, or to not hit your breakpoints.Alterable
P
0
  • Ctrl + Z is Undo obviously, but will also Undo auto formatting applied by studio.

Very useful when copying/pasting hardcoded tables that are spaced for readability. When you paste Studio will apply formatting and nothing lines up any more. A quick Ctrl-Z restores your nice alignment.

Penholder answered 19/9, 2008 at 8:11 Comment(0)
S
0

Here are a few which I didn't see listed yet:

  1. Quickly find selected text: When text is selected hit Ctrl + F3 and then subsequently F3 to quickly find that text in a given file
  2. Close multiple files: When you have many windows open and you want to clear only some of them (as apposed to 'close all but this etc.) Go to Window -> Windows... a dialog pops up and now you can select the windows you want to close
  3. Navigate to a particular file: When your solution has many files it can take a while to find a file in the solution explorer. No problem! Select your solution and start typing the name of the file and you are kindly directed to your file!
Stansbury answered 19/9, 2008 at 8:11 Comment(0)
D
0

Break on the line where exception occurs

If you want to break on the line where Exception has occured then you can use CTRL + ALT + E and select the check box against CLR under Thrown Column.

This will work even if the exception is handled by the user.

P.S:

I tried posting the screenshot but not able to do it since new users aren't allowed to post images. Sorry !

Dorelle answered 19/9, 2008 at 8:11 Comment(0)
B
0

I use it every time I open a file. And that's why I just hate regions.

Collapse to definition

Ctrl+M+O

Beetlebrowed answered 19/9, 2008 at 8:11 Comment(0)
E
0

A few that I know or haven't seen posted here.

  • Crtl + Space encourage Intellisense to complete a word.

  • Customize toolbox - Right click on toolbox, that brings up popupmenu > Choose items > Check/Uncheck boxes > Ok.

  • Start Visual Studio without splash page. Windows + R then type devenv /nosplash and press Enter.

Elan answered 19/9, 2008 at 8:11 Comment(0)
G
0

Task List Tokens

Configured task list tokens are retrieved later while opening task list window and select user comments option, this will display all user comments that contains configured tokens.

This will be so useful if you try to retrieve TODO comments for example.

To use it; Tools --> Options --> Environment --> Task List, add required tokens.

Gillian answered 19/9, 2008 at 8:11 Comment(0)
A
0

Ever want to see all the implementations of one interface member? Use "Call Hierarchy"!

Arabelle answered 19/9, 2008 at 8:11 Comment(1)
only 2010, this topic is about 2005-2008Halftrack
C
0

Just found out back and forward buttons on my mouse moves back or forward one document.

Think I was wrong about this one. Only happens when searched for stuff.

Choose answered 19/9, 2008 at 8:11 Comment(0)
H
0

I just wanted to copy that code without the comments.

So, the trick is to simply press the Alt button, and then highlight the rectangle you like.(e. g. below).

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        //if (e.CommandName == "sel")
        //{
        //    lblCat.Text = e.CommandArgument.ToString();
        //}
    }

In the above code if I want to select :

e.CommandName == "sel"

lblCat.Text = e.Comman

Then I press ALt key and select the rectangle and no need to uncomment the lines.

Check this out.

Hedonics answered 19/9, 2008 at 8:11 Comment(0)
P
0

I updated my code flipper, I posted earlier. I added support for ASP Controls.

Larry

Pineapple answered 19/9, 2008 at 8:11 Comment(0)
F
0

  • Print the shortcuts from http://www.microsoft.com/downloads/details.aspx?FamilyID=6bb41456-9378-4746-b502-b4c5f7182203&DisplayLang=en">the Microsoft page and put them next to you. Try to learn a new one every day. You'll find all shortcuts already mentioned here + lots more. Some very useful contain formatting a code block, commenting, navigate between pages,...
  • Get Resharper, it's a plugin which whill greatly increase your efficiency. If you use Resharper, you can find a list with shortcuts.
  • Frankiefrankincense answered 19/9, 2008 at 8:11 Comment(0)
    D
    0

    Here's an old blog article on some of the hidden debugger features in the expression evaluators.

    Denary answered 19/9, 2008 at 8:11 Comment(0)
    C
    0

    Vertical selection with Ctrl-Left Click is pretty useful sometimes...

    Canadianism answered 31/8, 2009 at 5:43 Comment(0)
    O
    0

    Shift + Delete to cut whatever line the cursor is on.

    I use this all the time to delete whole lines of code.

    Oedema answered 31/8, 2009 at 5:56 Comment(1)
    Do you know the hot key to delete the whole line without putting it into clipboard?Arabelle
    C
    -1

    After having read through all these marvelous (and some repetitive) posts, I have some to add that I don't think I saw:

    CTRL+Z = undo

    CTRL+Y = redo

    ;-)

    Also, don't forget to modify the keyboard shortcuts! Tools > Options > Environment > Keyboard

    LOTS of goodies! I have F9 == stepinto, f10 == step over and f11 == step out. VERY useful.

    Another not cited that I use somewhat often (although most people probably have a toolbar with this button): f6 == Build Solution.

    Enjoy!

    Catheterize answered 19/9, 2008 at 8:11 Comment(2)
    Also.. Ctrl+S to save the current file?Skilling
    Only a fool would use CTRL+S to do that. You must use CTRL+Shift+S to save ALL files! But really, these are trivial, I only will put the ones that are used frequently.Catheterize
    I
    -4

    Visual Assist, in general, while a bit OT for this question, is a great app and really helps with the day-to-day running of visual studio. Their open-any-file and find-any-symbol windows are particularly awesome.

    Intermixture answered 19/9, 2008 at 8:11 Comment(0)

    © 2022 - 2024 — McMap. All rights reserved.