260

What is the keyboard-shortcut that expands the menu, from the little red line, and offers the option to have the necessary using statement appended to the top of the file?

JΛYDΞV
  • 8,532
  • 3
  • 51
  • 77
Bramha Ghosh
  • 6,504
  • 4
  • 30
  • 29

6 Answers6

412

Ctrl + . shows the menu. I find this easier to type than the alternative, Alt + Shift + F10.

This can be re-bound to something more familiar by going to Tools > Options > Environment > Keyboard > Visual C# > View.QuickActions

Aaron Small
  • 1,682
  • 1
  • 11
  • 6
Orion Adrian
  • 19,053
  • 13
  • 51
  • 67
  • 6
    Yup, I guess it's what you're used to. I have no difficulty with Alt+Shift+F10 whereas Ctrl+. feels totally alien. I guess we'll accept anything given enough conditioning. :D – Jeff Yates Sep 29 '08 at 14:44
  • 6
    I have one of the Microsoft keyboards with their Function lock... man I hate that thing. – Orion Adrian Sep 29 '08 at 14:49
  • 1
    I have one of those at home. Function lock was a dumb idea. – Jeff Yates Sep 29 '08 at 14:50
  • 3
    Wow, didn't know about Ctrl+. or Alt+Shift+F10, but always wondered if there was such a short-cut. I also have a function lock keyboard, but it always remembers its state, so no problem here (Microsoft Natural Ergonomics Keyboard 4000). – OregonGhost Sep 29 '08 at 15:20
  • 1
    ctrl+ seems to hilight to the end of the line for me... I'm not sure why it's different. – justin.m.chase Mar 11 '11 at 04:00
  • 1
    @justin: You may have some kind of productivity plug-in that's stealing the shortcut, such as CodeRush or R#. – Jeff Yates Mar 11 '11 at 19:01
  • Just in case you wonder why it's not working, note that Ctrl+ does not work. It has to be the . next to the , – demoncodemonkey Nov 04 '11 at 10:49
  • As an additional note, it works with a french keyboard (AZERTY) using Ctrl + ";". As a reminder, "." is Shift + ";" on this keyboard. – Vincent Robert Jun 26 '12 at 14:35
  • I Need macro for this to automatically do it in all files in a solution – Tamilmaran Apr 30 '13 at 09:10
  • As said by Gawie below, this is all mapped to a command named "View.ShowSmartTag". Instead of using an uncomfortable shortcut, you can find the command and remap it to something that makes sense to you! – pghprogrammer4 May 06 '14 at 19:48
  • 1
    Your cursor will have to be on class/interface name you typed for this to work. – Pranav Mahajan Sep 19 '14 at 12:30
  • 1
    Tried both shortcuts in `Visual Studio 2013` and none of them worked. Does the shortcut exist for current version? – Mostafiz Rahman Feb 22 '15 at 22:13
  • @mostafiz It does work in VS 201. However, you may have a different keyboard layout than this question presumes due to manual settings, plug-in; extension changes; or different initial or inherited settings. – Orion Adrian Mar 06 '15 at 20:25
  • Works fine in VS2013 with the default keyboard mapping (can be changed in Options->Environment->Keyboard) – rustyx Jun 11 '15 at 14:52
  • Thanks! I was looking for a way to change the shortcut because both default ones (Ctrl+. and Alt+Enter) are for right hand which I use to navigate with mouse or arrow keys – aunoum May 22 '17 at 12:01
37

Alt + Shift + F10 will show the menu associated with the smart tag.

Jasper
  • 2,166
  • 4
  • 30
  • 50
Jeff Yates
  • 61,417
  • 20
  • 137
  • 189
  • 2
    Your cursor will have to be on class/interface name you typed for this to work. – Pranav Mahajan Sep 19 '14 at 12:29
  • Yes. And it has to be the mouse cursor too, not just the keyboard cursor, and having to move your mouse cursor there in order to access it completely defeats the point of having a keyboard shortcut at all. – Neutrino Mar 16 '17 at 09:56
  • @Neutrino That's certainly not the case for me. The mouse cursor has nothing to do with it. – Jeff Yates Mar 17 '17 at 04:55
27

I can highly recommend checking out the Visual Studio plugin ReSharper. It has a QuickFix feature that does the same (and a lot more).

But ReSharper doesn't require the cursor to be located on the actual code that requires a new namespace. Say, you copy/paste some code into the source file, and just a few clicks of Alt + Enter, and all the required usings are included.

Oh, and it also makes sure that the required assembly reference is added to your project. Say for example, you create a new project containing NUnit unit tests. The first class you write, you add the [TestFixture] attribute. If you already have one project in your solution that references the NUnit DLL file, then ReSharper is able to see that the TestFixtureAttribute comes from that DLL file, so it will automatically add that assembly reference to your new project.

And it also adds required namespaces for extension methods. At least the ReSharper version 5 beta does. I'm pretty sure that Visual Studio's built-in resolve function doesn't do that.

On the down side, it's a commercial product, so you have to pay for it. But if you work with software commercially, the gained productivity (the plug in does a lot of other cool stuff) outweighs the price tag.

Yes, I'm a fan ;)

Tony Tuttle
  • 612
  • 7
  • 23
Pete
  • 12,206
  • 8
  • 54
  • 70
14

In Visual Studio 2010 you will find the keyboard command to resolve namespaces in a command called View.ShowSmartTag. Mine was also mapped to Shift + Alt + F10 which is a lot of hassle - so I usually remap that promptly.

On Pete commenting on ReSharper - yes, for anyone with the budget, ReSharper makes life an absolute pleasure. The fact that it is intelligent enough to resolve dependencies outside the current references, and add them both as usings and references will not only save you countless hours, but also make you forget where all framework classes reside ;-) That is how easy it makes development life... Then we have not even started on ReSharper refactorings yet.

DevExpress' CodeRush offers no assistance on this regard; or nothing that is obvious to me - and DevExpress under non-expert mode is quite forthcoming in what it wants to do for you :-)

Last comment - this IDE feature of resolving dependencies is so mature and refined in the Java IDE world that the bulk of the Internet samples don't even show the imports (using) any more.

This said, Microsoft now finally has something to offer on this regard, but it is also clear to me that Microsoft development (for many of us) has now come full circle - the focus went from source, to visual designers right back to focus being on source again - meaning that the time you spend in a source code view / whether it is C#, VB or XAML is on the up and the amount of dragging and dropping onto 'forms' is on the down. With this basic assumption, it is simple to say that Microsoft should start concentrating on making the editor smarter, keyboard shortcuts easier, and code/error checking and evaluation better - the days of a dumb editor leaving you to google a class to find out in which library it resides are gone (or should be in any case) for most of us.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Gawie Kellerman
  • 151
  • 1
  • 4
  • That's what I was looking for! What's the command called so I can remap it. Kudos for finding its name... really obscure. – swinefeaster Apr 21 '13 at 01:23
6
  • Context Menu key (one one with the menu on it, next to the right Windows key)
  • Then choose "Resolve" from the menu. That can be done by pressing "s".
James Curran
  • 101,701
  • 37
  • 181
  • 258
0

It's ctrl + . when, for example, you try to type List you need to type < at the end and press ctrl + . for it to work.