Eclipse's Ctrl+click in Visual Studio? - visual-studio

After working for a few days with Eclipse Java I totally got addicted to pressing Ctrl and clicking on an identifier to go to its definition. Since then I've been looking for a way to achieve this in Visual Studio as well.
I realize VS has right click, Go to definition, and that F12 does the same. I also realize that Visual Assist does something similar with Alt + G. Yet none of these are as perfect as Ctrl + click.
I've actually tried my luck for a few hours trying to write a VS plugin to do it but didn't get anywhere in the time frame I thought reasonable for this.
Does anyone know how this could be achieved? A ready plugin? A macro of some kind?

If you use Visual Studio 2010, you can use the free
Visual Studio 2010 Productivity Power Tools from Microsoft to achieve this.

I use visual studio 2013 and 2015, I installed Go To Definition. To install this extension navigate on TOOLS -> Extensions and Updates.

I'll answer the commentors who asked about the difference between Ctrl-click and F12.
Ctrl-click workflow:
Move hand to mouse
Move mouse to hover over variable name
Other hand holds down Ctrl key while you click
Move mouse to position cursor, highlight, right-click, or whatever
Move hand back to keyboard to continue typing
F12 workflow
Move hand to mouse
Mouse mouse to hover over variable name
Move hand back to keyboard
Hit F12 key
Move hand back to mouse
Move mouse to position cursor, highlight, right-click, or whatever
Move hand back to keyboard to continue typing
If you assume the cursor is already positioned on the desired variable, F12 is better. However, that's rarely the case. Also, if you stop after this specific action, assuming you want hands back at the keyboard, the cost is the same. But if you keep in mind that you probably had a reason for wanting to go to the definition, the Ctrl-click workflow saves you an instance of moving between the keyboard and mouse.

Visual Assist supports Ctrl+Click as of June 2009 (build 1727). Activate Ctrl+LeftClick in VA Options | Advanced | General. (See the comment below.)

If you have Visual Studio 2010 you can use "Go To Definition" by Noah Richards.
http://visualstudiogallery.msdn.microsoft.com/en-us/4b286b9c-4dd5-416b-b143-e31d36dc622b

oh man, just install resharper!! (vs plugin) with it installed you just go and Ctrl + click to go to definition.
this is not the only thing resharper does, try it out free!!!

I use the built in options (F12, Right-click -> Go to definition) but I know a lot of the guys at my company use Resharper and it definitely has this functionality.

Microsoft released a Visual Studio 2010 extension named "Productivity Power Tools" which now adds Ctrl+Click functionality. So if you're like me, and hate installing third-party addons, you can now have the same functionality!

Another option with VS (besides F12 and right-click > Go to Def) is add the code definition pane (View > Code Def Window). This is essentially another editing pane that shows the code for the current symbol - no need to Ctrl-click or anything. I keep it pinned to my secondary monitor. Any time I need to see the implementation for a symbol I just click it and look over.
Another nice thing about F12 is you can also do ShiftF12 to find references to a symbol and F8 through them. The two go together like love and happiness.

I prefer to bind Go To Definition to CtrlD. This makes it extremely easy to use either with both hands on the keyboard (CtrlD to go tho the definition of the symbol under the cursor) or one hand on the keyboard and one hand on the mouse (Click on a symbol, then CtrlD).

All in all, both VS and Eclipse have weird key shortcuts.
I just had to respond, too: F12 is far too right on the keyboard and you have to leave the the mouse right hand for the keyboard to use it. As a long time VS user I just didn't find it until I searched for the Ctrl+Mouse equivalent in Eclipse. It's completely borked. OK? No need to argue. (The same goes for F3 in Eclipse going for definition. ???? Why the face??? It's FIND NEXT for Pete's sake. But this can be removed after mastering the Eclipse keyboard shortcut system in the course of a few years.)
Anyway, as has been said here before, Microsoft has already understood this can be an issue for new programmers coming in from Eclipse, so they provided the Power Tools (I followed the link up above).
http://visualstudiogallery.msdn.microsoft.com/d0d33361-18e2-46c0-8ff2-4adea1e34fef/

If you are using Visual Studio 2017, you can use Productivity Power Tools 2017

I don't work in VS much, so I haven't used it, but I've heard incredibly good things about Resharper from everyone I know who does. Everyone has told me it's worth every penny, and significantly improves efficiency in Visual Studio. I think it has a feature like what you're looking for, along with a TON of others.

Related

What is the command for promoting a peek preview to document?

When I'm in peek preview, I sometimes wish to promote it to document. It's done by mousing on the icon as shown below.
On occasion (most of the occasion, in fact), my mouse is tired and wants me to use my keyboard for such promotion to document. According to the wisdom on the net, it's achieved by CtrlAltHome.
In my VS, there's nothing assigned to the key combination, so I'm guessing someone snack in and changed that without my permission. However, to restore it, I need to know what the command in Tools | Options | Environment |Keyboard is called.
I can't find anything appropriate there (I've tried different variations of the MS's description of the command: "Promote the Peek Definition window to a regular document tab").
So, what is it called? If it differs between versions, I'd like to know the name for each, where the peeking is avaialble (started in VS13, if I'm not mistaken).
Given the meaningful effort I've put into composing the image, every and each can clearly see that it's a crucial and important matter, given the circumstances.
In Visual Studio 2013 the command name is Window.KeepTabOpen.
I had the same issue but on reverse. I hate the Peek Definition and didn't know how to get rid of it. Well, I found it. In Visual Studio 2017 you need to go to Tools -> Options -> Productivity Power Tools -> General -> Control click options. There you need to check/uncheck the Control click shows definitions in Peek
Hope it helps!
PS. In order to see Productivity Power Tools you need to get it first using NuGet
A workaround for this (for Visual Studio 2015) is the following:
With focus on the peek window to open/dock:
Close peek window
Esc
Go to definition
F12
Pin tab
Alt+-, P
If there are multiple/nested peeks, then replace step 1 with:
Previous peek window
Ctrl+Alt+-

visual studio 2010 - jumping to method definition with the mouse

Moving from years of work on intellij to VS2010 (with resharper ) I cant stop clicking the mouse scroll wheel in order to jump to function or variable definition (as in intellij or F12) only to find that this feature does not exist.
Is there a way to set this feature ?
Is there a diffent way to do it with the mouse ?
Thanks.
EDIT - Thanks guys - but I wanted to set the mouse scroll press
F12 will go to definition. Power productivity tools comes with a ctrl+click to go to definition.
Power productivity tools: http://visualstudiogallery.msdn.microsoft.com/d0d33361-18e2-46c0-8ff2-4adea1e34fef
or F12 ------------------------------------
Right Click the variable and you will have an option to see definition:-
if you're really adamant about it, you can check here http://www.codeproject.com/Articles/25369/Forward-Backward-navigation-with-the-mouse-thumb-b to put you in the track for a do-it-yourself approach

What is the difference between Ctrl+R, Ctrl+D and Ctrl+R, D visual studio shortcuts?

The question itself is in the title. See screenshots.
When I'm using those both shortcuts, my Visual Studio 2010 does exactly the same action (debug tests). However, the shortcuts are assigned for different buttons.
What am I missing?
UPDATE:
Here is my keyboard customizations in "Tools" - "Customize" - "Keyboard".
There is no difference, VS treats Ctrl+R,Ctrl+D and Ctrl+R,D as the same command. There's ancient history behind this behavior, going all the way back to an old text editor named Wordstar. Which used control key chords like that. Also adopted by Borland, a company that Microsoft was fiercely competitive with. And by me, I still use it, got a weird left pinky to show for it.
You'll have to assign a different chord for the other command.
The difference is that when using CTRL+R, CTRL+D, the test runner runs the tests with the debugger attached.
This means that you can set breakpoints in the tests and step through the code. It is very useful at times.
EDIT: I think I missed the fact that you probably know about the concept of debugging tests. As Fishermaen points out, the shortcuts might be messed up. Do you have Resharper or any other 3rd party tool that alters these settings perhaps?
Check in "Tools" - "Customize" - "Keyboard" if the shortcuts are wired up correctly.

F6 for compiling?

I have become accustomed to using F6 to compile the current document. A third-party install appears to have turned this function off. (F6 no longer does anything.)
Can anyone tell me how to get it back?
I'm using VS2008
Tools > Options > Keybord
This dialog lets you bind keyboard shortcuts to your heart's content. BTW this is how you bind keyboard shortcuts to custom IDE macros as well.
Thanks. The dialog: Tools > Options > Keybord
Allowed me to set the keyboard back to Visual C# 2005. So far, this seems to be what I wanted.
VMware's integrated debugging tool did this to me too. You can change this back to whatever you want, but every time you restart Visual Studio your keyboard shortcuts will be changed again.
The only way I could fix this was to remove the VMware debugging tools.
Its become a habit for me to use Ctrl + Shift + B to build my solutions. I know this doesnt answer your question, but I thought I would point it out.
Another keyboard shortcut is use constantly is Alt + Shift + F10. It opens the drop menu from the little red square under a change (the autocorrect type thing, I'm not sure what its called, also works for autocorrect in all the MS apps)

Visual Studio keyboard-shortcut for automatically adding the 'using' statement

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?
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
Alt + Shift + F10 will show the menu associated with the smart tag.
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 ;)
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.
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".
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.

Resources