149

I would like to have a keyboard shortcut in IntelliJ IDEA that has the following effect: the tree in the project tool window expands to show the currently open class (or file), and this class becomes selected in the tree.

Is this possible?

Pang
  • 9,564
  • 146
  • 81
  • 122
lbalazscs
  • 17,474
  • 7
  • 42
  • 50
  • Possible duplicate of [Locate current file in IntelliJ](https://stackoverflow.com/questions/1086041/locate-current-file-in-intellij) – Suma Jul 25 '17 at 17:00

7 Answers7

223

Navigate (View in older versions)| Select In... (Alt+F1), Project View (Enter).

It's also possible to enable Autoscroll from Source option in the Project View so that current file is automatically selected.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • 3
    @4myle More accurately, it doesn't work on Gnome, because Gnome maps Atl-F1 to show the Gnome Activities Overview by default (which is redundant if you have a Windows/Cmd key on your keyboard). Just go into Settings > Keyboard > "Show the activities overview", click and then hit Backspace to clear the keyboard mapping. Then it will work. – Dan Feb 27 '18 at 18:45
  • @CrazyCoder do you know the way to enable Autoscroll from Source for the class that are in some dependent library/jar on the classpath (not directly in the source code). – Dhruv Mar 13 '19 at 05:26
  • Default alternative hotkeys (on linux, useful if alt+f1 is mapped elswhere by the OS): alt+shift+1 – Echsecutor Mar 02 '22 at 08:32
216

IntelliJ IDEA 2019

Left click on the wheel > Always Select Opened File

Always Select Opened File

There is also: Open Files with Single Click - the selected file from the tree view will be opened in the right side.


Old IntelliJ versions

Right click on Project/Packages area > Autoscroll from Source

enter image description here

or

Left click on the wheel > Autoscroll from Source

enter image description here

There is also: Autoscroll to Source - the selected file from the tree view will be opened in the right side.

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
  • 5
    Did you read the accepted answer until the end? Anyway, +1 for you because you also included a screenshot :) – lbalazscs Oct 10 '14 at 23:32
  • 15
    Yes, I read it, but I posted that from 3 reasons: 1. `in the Project View` is ambiguous, because it can include or not the tree that contains the files. 2. I added that it also works if we have Packages view instead of Project view. 3. As you mentioned, there are some people that prefer a visual representation for this. – ROMANIA_engineer Oct 11 '14 at 10:46
  • Thanks a million! Everytime I find myself amazed how Idea managed to hide this feature... – Denn0 Dec 23 '19 at 09:27
  • When 'Always select opened file' is ticked and the selected file is not located in the middle of project tree(because you scrolled it previously), you can have issues when switching back to IntelliJ window from some other window..possibly hijacking you back click. The selected file will be autoscrolled to the middle. To prevent: set `ide.autoscroll.from.source.on.focus.gained` to false in the Registry – sanya Jul 05 '21 at 08:07
32

Try Alt F1(Select Target dialogue) + Enter.

Vic
  • 21,473
  • 11
  • 76
  • 97
6

Click at this icon click on this icon on the top of tree-box.

deldev
  • 1,296
  • 18
  • 27
1

you can do this also using the upper dynamic menu that change for every opened file. just click twice on the last folder and the file will be on the same folder branch

enter image description here

also good for pycharm

dsaydon
  • 4,421
  • 6
  • 48
  • 52
1

IntelliJ 2023.1

To do this by default, right-click "Project" and select "Always Select Opened File". You might need to re-enable this when you open new projects.

select open files for the project

If you have NOT enabled "Always Select Opened File" as discussed previously, then you can click "Select Opened File" to do it for the current file. You will not see the "Select Opened File" icon if you have enabled "Always Select Opened File" for the project.

select open files for a single file

dutoitns
  • 1,949
  • 1
  • 26
  • 32
  • 1
    I guess we would have a new answer every year or every new version of Intellij.IDEA ! LOL. Their stuff don't stay at the same spot at the new version. If you clicked the robin wheel like the previous answer said, you'll be running the program not putting you into the settings. – Jenna Leaf Aug 15 '23 at 17:51
0

You can also make your own key combo to the "select in tree view" via prefs. I often do: shift + cmd + a and then just write select in.. and then press enter.

Sentry.co
  • 5,355
  • 43
  • 38