Choose between open declaration/implementation on Ctrl + click in IntelliJ IDEA - 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.
How can I achieve the same / a similar behavior in IntelliJ IDEA ?

There is not a built-in option for this. You would need to configure a custom quick list to do such.
Open the Settings dialog and go to "Quick Lists" (It's under "Appearance & Behavior" in IDEA 14)
Click the add button to the right of the middle pane
Give your list a name
Click the add button to the right of the far right pane (where is reads "no actions")
Add the Go to Declaration action (Main Menu > Navigate > Go to Declaration)
Add the Go to Implementation(s) action (Main Menu > Navigate > Go to Implementation(s))
Click Apply
Go to Keymap in the settings
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
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

I was looking for the same thing, because I was also used to it in Eclipse. Nevertheless, in 99% of the cases, I went to the implementation. If that's your case too, you may consider changing the Ctrl+click shortcut in IntelliJ:
Open File → Settings... → Keymap
Search for "implementation", and identify the item "Main menu → Navigate → Implementation(s)" in the list
Right-click the item and choose "Add Mouse Shortcut"
Add the Ctrl+click shortcut by making a Ctrl+left click on the window
When hitting the OK button, you have two choises :
Remove the existing shortcut (opening the declaration)
Leave the existing shortcut : In that case, when using then Ctrl+click, both the declaration and the implementation will be opened (at least when they are in different files)
I know this answer comes like 2 years too late, but hopefully it may help others?
EDIT : This shortcut also applies when you want to navigate to the declaration of a super class. Therefore, my "99%" first declared above drops a bit.
I've added the ctrl + right-click as a shortcut to go the declaration (which conflicts with no other shortcut - but you need a mouse with at least two buttons...).

If you select the method and hit Ctrl+T it will show the implementations of the methods. You can click on the options to navigate to that implemented method. Hope this helps.

On mac you can open the implementation(s) with command + option + click. Right -click on the method and check "go to" for the other options and shortcuts you might need.

My IntelliJ (2016.2) shows the declaration of a method (in a PHP interface) as one of the implementations in the implementation popup, so maybe you can do this all from the Implementations popup now.

Related

Keyboard shortcut to navigate between IntelliJ views

In IntelliJ, there are some underlined numbers on the side menus :
1: Project
7: Structure
Like below :
So there is probably a keyboard shortcut which allows to navigate from one view to another by just entering the view number.
I tried the different digits with Ctrl, Ctrl+Shift, Ctrl+Alt etc but could not find the right shortcut.
How can I easily navigate between those views?
The shortcut is Alt + [number]
ps. There's a plugin force-shortcuts if you wanna replace your mouse click actions with shortcuts (https://github.com/treytrahin/force-shortcuts-intellij-plugin). It's super annoying but you learn really fast. And by the way here are such plugins to most editors and IDEs.
ALT+F1 opens a window where you can choose one of the views by pressing the corresponding number.
Info: It actually opens the selected file in the selected view - which is not that bad maybe - but not 100% what you want?
Also there are cool things like pressing C to open a file chosen in Project Explorer directly in Explorer for example.

How to trigger Eclipse-like cmd+click in IntelliJ?

How do i trigger the cmd + click behaviour (Go to Class, go to declaration etc) in IntelliJ when my current keymap uses Eclipse (MacOS)?
I'm currently switching from Eclipse/STS to IntelliJ. So far, i've changed the keymap to use Eclipse (MacOS), so most of the familiar keyboard shortcuts i use still works.
control + click does the functionality that i want using Eclipse (MacOS) keymap but this also triggers system behaviour of right click, so menu pops out the same time that the go to class/variable triggers. Is there a way i can set or use cmd + click to trigger the desired behavior?
Go to Preferences > Keymap.
You have to copy the Eclipse (MacOS) keymap to a new name, in order to make changes: select the Eclipse (MacOS) keymap, press the Copy button and give it a new name, e.g. Eclipse (MacOS) 2.
Then click into the filter field, enter declaration, then in the tree area do right-click on the Main menu > Navigate > Declaration line in order to activate the context menu. The result should look like this:
Select Add Mouse Shortcut from the context menu, a dialog opens. Perform into this dialog the key + click combination you wish to add, in your case cmd + click:
Confirm the new Mouse shortcut with Ok, then close the Preferences dialog also with Ok or Apply. Done.
Note: you can delete the ctrl + click mouse shortcut, if you wish to not use it by mistake, by selecting Remove ^Button1 Click in the context menu.

Move file from one editor window to another (split mode)

Is it possible to move a file (already opened) from one editor to another in split mode without using mouse and without using tabs (I have tabs disabled).
Example of what i want to accomplish. I enabled split mode (vertical) and opened file X in left editor. I want to move this file X to right editor because I already have file Y int left editor.
I found the command Move to opposite group which works fine only when tabs are enabled. When tabs are disabled (my case) call Move to opposite group force split mode to disappear.
Goto File->Settings
Then Keymap
Type in the searchbox "Move To Opposite Group"
Assign a shortcut
Also useful is "Goto Next Splitter" which allows you to switch between your Splitter.
But you'll hardly find a shortcut which is not already occupied.
I used Ctrl + NumPad+ for "Move To Opposite Group" and Ctrl + ArrowRight for "Goto Next Splitter"
You'll be notified that this shortcut is already in use, but you can ignore that. I had no conflicts so far
I agree with David Viehtauer and would add to his setup. This also won't work with tabs disabled, but has become essential to my workflow.
My prefered setup under Preferences > Keymap:
Move Right: ⌃ + ⌘ + ↓
Move To Opposite Group: ⌃ + ⌘ + ↑
Goto Next Splitter: ⌃ + ⌘ + →
Goto Previous Splitter: ⌃ + ⌘ + ←
Move Right will create a new splitter and send your current tab to it (if you have more than one tab on your current splitter). Once your file is in a new splitter you can go between your splitters with the Goto Next Splitter and Goto Previous Splitter shorcuts above. Now, using the Move To Opposite Group shortcut you can move your active tab to the preferred side.
Once you get familiar with this setup, you can quickly manage your tabs.
Action Open in opposite group is the closest solution I found.
Example of what i want to accomplish. I enabled split mode (vertical) and opened file X in left editor. I want to move this file X to right editor because I already have file Y int left editor.
After Open in opposite group action X will be opened in both editors. My workflow is "move" X to right editor and keep working in left editor.
My choice in this case was to use CTRL-SHIFT-a. I felt the command was not important enough to dedicate a shortcut to it.
As soon as the dialog appears, it is sufficient to type open opp and then you can already hit ENTER.
Here is another way to do this:
Put the cursor in the editor you want the class to display in
Bring up the search for class dialog (alt-o in my mac keymap, can't
remember if I customized this or not)
Search for your class
Select it then hit cmd-shift-enter, it will open in the editor your
cursor is in even if it is already open in another editor pane

Intellij IDEA: Hotkey for "scroll from source"

I can't find a hotkey for the feature "Scroll from Source".
What is the difference between Scroll from Source and Scroll to Source as well?
In the latest IntelliJ IDEA, there is a keymap entry called "Select in Project View" with no default shortcut. Just add a shortcut key to it. No need for a plugin.
tldr;
Alt + F1, then 1
First checkout your shortcut key for the "Select In.." item in the Navigate menu.
Click in the file you're editing, hit the shortcut key for "Select in".. then press 1.
I've changed the hotkey for select in to Alt + 1 so that my key combination is the easy to remember Alt + 1, 1
There is a plugin for this now.
It's called Scroll From source:
https://plugins.jetbrains.com/plugin/7606?pr='
This is now builit in see #Dimitrov answer
https://stackoverflow.com/a/42025214/961018
There's no configurable shortcut in the Keymap settings, and it does not appear in the "Enter action" dialog, so I'm pretty sure it's not (yet) configurable, even if I agree it would be very appreciable.
You can use the navigation bar Shortcut keys as well.
On Mac
Hit ⌘ + ↑ (command and up key)
Hit ← (left arrow)
Hit ⌘ + Enter
This will take you to the folder in project view.
It's worth having a play round with the navigation bar.
IntelliJ really have this covered :)
For ubuntu i did ALT+L (cause ALT + F1 is busy), then just enter.
If you are using JetBrains Rider, then the shortcut is Locate in Solution Explorer:
As a much much much much much better alternative to the scroll from source functionality you can use the Navigation bar.
Note: double clicking on the folder in the navigation bar will scroll to that folder in the Project view, (i.e. the same functionality as scroll from source).
You can show the navigation bar in the view menu, there's also a shortcut for each OS (cmd and up arrow ⌘ + ↑ on OSX, Alt + Home on Linux and Windows)
So it looks like this...
And it allows you to browse through the folder structure containing the file in focus in the main editor.
https://www.jetbrains.com/phpstorm/help/navigation-bar.html
https://www.jetbrains.com/idea/help/navigation-bar.html
https://www.jetbrains.com/webstorm/help/navigation-bar.html
In Ubuntu 18 you can disable shortcut Alt+F1, the super key(windows key) do same thing.
At moment i disable/changed this shortcuts of ubuntu
Alt+F7 --> windows+F7
Ctrl+Alt+L --> windows+L
Alt+F1 --> windows
Another better way:
The Shortcut is called Select in Projec View
The default shortcut is
CTRL+Alt+1
or you can edit this.
Source: https://intellij-support.jetbrains.com/hc/en-us/community/posts/206717285-Scroll-from-source-keyboard-shortcut-?flash_digest=77b77d09d61eff96f7d59697820dee45b2c2041c
UPDATE: Now you can easylly use Shift+Alt+1 in Gnome Keymap or Alt+F1 in Windows Keymap
Blockquote
If I understand correctly you don't want to toggle the option so much as trigger the file browser tool window with the selection being the currently edited file.
Just leave 'Scroll From Source' enabled and open the file browser with Command + 1 on OSX or CTRL + 1(i think) on Windows. The file browser sidebar will be selected and your selection will be highlighted.
This answer also explains the difference between Scroll To and Scroll From: How to make Scroll From Source feature always enabled?
In JetBrains Rider, this action used to be named Locate in Solution Explorer, but is now (v2019.2) named Locate/Select in Solution View and by default (at least with the built-in ReSharper keymap) bound to Alt+Shift+L.

Disable jump to file on ctrl+click at reference identifier

Is there any way to disable jumping to another file, which occurs when clicking on reference identifier (for example library method or module element) with CTRL key pressed down?
I'm often using mouse select with ctrl+c/ctrl+v and IDEA often mistakes this operation with jump operation.
Go to File > Settings > [IDE Settings] > Keymap
In the Keymap, go to Main Menu > Navigate > Declaration
Right click the Declaration entry and select "remove Ctrl+Button1 Click"
Note, if you are using a Default kymap, you will need to first copy (at the top) the keymap before you can edit it. You can only edit custom keymaps.
Click OK