Search code examples
intellij-ideakeymappingintellij-14

Choose between open declaration/implementation on Ctrl + click in IntelliJ IDEA


Details:

  • IDE: IntelliJ IDEA 14
  • O.S.:: Windows 7

If I want to navigate to the declaration of a method I can choose one of the following approaches:

  • press Ctrl + left click
  • right click > Go To > Declaration
  • press Ctrl + B

If I want to navigate to the implementation of a method I can choose one of the following approaches:

  • press Ctrl + Alt + left click
  • right click > Go To > Implementation(s)
  • press Ctrl + Alt + B

In Eclipse, if I press Ctrl and the mouse is over a method, a popup appears and I can choose what to do (go to Implementation/Declaration). If I press "left click" ( Ctrl is still pressed ) the first option will be chosen.

enter image description here

How can I achieve the same / a similar behavior in IntelliJ IDEA ?


Solution

  • There is not a built-in option for this. You would need to configure a custom quick list to do such.

    1. Open the Settings dialog and go to "Quick Lists" (It's under "Appearance & Behavior" in IDEA 14)
    2. Click the add button enter image description here to the right of the middle pane
    3. Give your list a name
    4. Click the add button enter image description here to the right of the far right pane (where is reads "no actions")
    5. Add the Go to Declaration action (Main Menu > Navigate > Go to Declaration)
    6. Add the Go to Implementation(s) action (Main Menu > Navigate > Go to Implementation(s))
    7. Click Apply
    8. Go to Keymap in the settings
    9. Under the "Quick List" node, find the Quick List you just created and map a short-cut (keyboard or mouse) to it. You can, of course, remap one of the shortcuts used by the Go to Declaration or the Go to Implementation(s) action
    10. Click OK to close out of the settings and give it a try.

    Note that in the quick list that opens, you will have numbers next to each action for quick selection.

    Edit: Adding a screenshot of final quick list for additional clarity

    enter image description here