在 Visual Studio 中单击 Eclipse 的 Ctrl + ? ?

在使用 EclipseJava 工作了几天之后,我完全沉迷于按 Ctrl并单击一个标识符进入它的定义。从那时起,我就一直在寻找在 VisualStudio 中实现这一点的方法。

我意识到 VS 有右键单击,转到定义,而且 F12做同样的事情。我还意识到 Visual Assist 与 Alt + G有类似的功能。然而,这些都没有像 Ctrl + click 那样完美。

实际上,我已经尝试了几个小时,试图编写一个 VS 插件来完成这项工作,但没有在我认为合理的时间范围内取得任何进展。

有人知道这是如何实现的吗? 一个现成的插件? 某种宏?

38569 次浏览

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.

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.

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.

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.

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

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

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

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

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

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!

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/

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

enter image description here

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