Locate current file in IntelliJ - keyboard-shortcuts

How do I locate the current file in the project structure? (Similar to Visual Studio's Ctrl + Alt + L). What is the name of the operation (so I can define it in the keymap)

Alt + F1 (or Alt + Shift + 1 for linux) almost does what you want. You need to hit Enter afterwards as IDEA allows multiple "targets" for navigation (project structure, file structure etc).
(Note you can also set AutoScroll to Source and AutoScroll from source using the two "boxes with arrows" buttons above the project structure view but this can get annoying when it shoves you into the JDK source because you followed a reference to java.io.File.
The keymap defines it as Select current file or symbol in any view.

You can also click the little cross hairs button in the projects pane:
Note that the symbol won't be shown if Always Select Opened File (previously Autoscroll from Source) option is enabled.

Click the gear in the Project tool window and then Always Select Opened File (previously Autoscroll From Source)

"Select in project View"
Little to no memorization required, reusable for every action in Intellij:
Use Find Action:
Press Shift + cmd + A (Pretty sure
it's Shift + Ctrl + A for Windows
and Linux)
Type select in...
Select Select in Project View in the suggestion list

Do following will select your file automatically all time.
Right click on Project/Packages area > Autoscroll to Source.
Right click on Project/Packages area > Autoscroll from Source.
Please find image below.

I am using IntelliJ IDEA 2016.2 Ultimate.
Alt+F1, then press 1

And make it autoscrollable from source without hitting shortcuts every time How to make Scroll From Source feature always enabled?

There is no direct shortcut for such operation in IntelliJ IDEA 14 but you can install the plugin and set it the keyboard shortcut to the function that called "Scroll From Source" in keymap settings.

In addition to the other options, in at least IntelliJ IDEA 2017 Ultimate, WebStorm 2020.2, and probably a ton of other versions, you can do it in a single shortcut.
Edit preferences, search for Select in Project View, and under Keymap, view the mapped shortcut or map one of your choice.
On the Mac, Ctrl + Option + L is not already used, and is the same shortcut as Visual Studio for Windows uses natively (Ctrl + Alt + L, so that could be a good choice.

Open the project explorer ( default left side )
Click on the tiny wheel setting button
Mark Auto scroll from source option.
Boom! You are done.

If you are using Mac(OSX)
Based on the current tab, to select the file on project is : FN + OPTION + F1
Then in the popup you can Select in: Project View > Select In: Project

in PyCharm 2021 this hotkey named Select File In Project View

In Intellij Idea Community edition 2020.1 :
Right click on project header
Select 'Always Select Opened File'

In 2023 there is still no default shortcut for locating the current file in the Project view. However it is easy to set up a custom shortcut for it.
Open Settings, go to Keymap and search for "Select file in project view". It should be in the "Other" section and should have a crosshair icon. Right click on it and select "Add keyboard shortcut". I set it up to CTRL + SHIFT + L, but of course any unmapped key combination will work.
Enjoy! For me this is a very often used feature and having a shortcut for it is a significant productivity boost.

Related

How to quickly switch different project in intellij

I have to open each intellij instance for each application. And switch between these project are not so efficient. (there's no dependency between these project, so I can not add them into one project). I just wonder is there efficient way to switch between different projects in intellij.
OSX: Press CMD + `
Windows/Linux: Press cntr + `
https://www.jetbrains.com/help/idea/creating-and-managing-projects.html#switch-projects
if you have several opened projects: https://www.jetbrains.com/help/idea/opening-multiple-projects.html
you can use:
Next Project Window: Cntrl + Alt + {
or
Previous Project Window: Cntrl + Alt + }
Edit
jebrains update their Switching Between Open Projects:
https://www.jetbrains.com/help/pycharm/switching-between-projects.html
Next Project Window: Cntrl + Alt + ]
or
Previous Project Window: Cntrl + Alt + [
Set up a keymap shortcut to "Manage Projects...".
This brings up a window that you can type into to quickly search recent projects. It includes currently open projects as well as previously closed projects.
Use search everywhere command (shift + shift) and type Open Recent - you will be able to switch to one of your recent projects.
You could also configure any shortcut you want for this action.
To create shortcut, go to Preferences->Keymap and find Main menu->File->Open Recent.
Try this https://github.com/krasa/FrameSwitcher.
Switching intelliJ windows by searching project name.
If you're a MacOS user: As well as the Command+` and Command+Shift+` keyboard shortcuts which IntelliJ offers to toggle between IntelliJ windows, the OS-level Control+↓ keyboard shortcut is an excellent way to see and navigate between windows of the current app. The screenshot below shows the view which it offers. If you turn on App Exposé in your Trackpad preferences, you can also get to this view by swiping down with three fingers.
To switch between open projects, you can use the following commands of the Window menu:
Window | Next Project Window Ctrl+Alt+]
Window | Previous Project Window Ctrl+Alt+[

Shortcut for locate current file in Project Explorer in IntelliJ?

I read this post:
Locate current file in IntelliJ
Still the problem is that I do not want to have Autosccroll from Source enabled because my Project Explorer will be jumping up and down. Rather I need a shortcut to locate the current file in the Project explorer when I need to. ALT + F1 does work but you need to select from a context menu where you would like the file to be shown. In Resharper for example the shortcut is ALT+SHIFT+L but I am not able to find such a shorcut in IntelliJ?
There is no shortcut for this action in IntelliJ IDEA other than Alt-F1.
There is no default way of doing this.
I can think of 4 options:
You can install the plugin 'Scroll From Source' which will allow you set such a shortcut in the keymap settings (Default: Meta + Ctrl + S)
Use the target symbol in the project explorer, no shortcut but is default option.
Get used to having to press Alt + F1 and then Enter
Record a macro for the above key presses but this may be unreliable. You could then assign a shortcut key to play this marco.

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.

How to automatically navigate to current class in IntelliJ IDEA Project Tool Window?

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?
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.
IntelliJ IDEA 2019
Left click on the wheel > 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
or
Left click on the wheel > Autoscroll from Source
There is also: Autoscroll to Source - the selected file from the tree view will be opened in the right side.
Try
Alt F1(Select Target dialogue) + Enter.
Click at this icon on the top of tree-box.
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
also good for pycharm
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.

How do I create a new class in IntelliJ without using the mouse?

Is there a way to create a new class in a desired location without using the mouse in IntelliJ?
I understand there is no keyboard binding in the default keymap.
If you are already in the Project View, press Alt+Insert (New) | Class. Project View can be activated via Alt+1.
To create a new class in the same directory as the current one use Ctrl+Alt+Insert (New...).
You can also do it from the Navigation Bar, press Alt+Home, then choose package with arrow keys, then press Alt+Insert.
Another useful shortcut is View | Select In (Alt+F1), Project (1), then Alt+Insert to create a class near the existing one or use arrow keys to navigate through the packages.
And yet another way is to just type the class name in the existing code where you want to use it, IDEA will highlight it in red as it doesn't exist yet, then press Alt+Enter for the Intention Actions pop-up, choose Create Class.
You can also use: ctrl+alt+insert
With Esc and Command + 1 you can navigate between project view and editor area - back and forward, in this way you can select the folder/location you need
With Control +Option + N you can trigger New file menu and select whatever you need, class, interface, file, etc. This works in editor as well in project view and it relates to the current selected location
// please consider that this is working with standard key mapping
For Mac Os, command + 1 , then press control + return
On Mac OS 10.14.5, Idea Intellij 2019.1.3 - Press command + 1 to navigate to project files then press control + n
On Mac you can navigate to the location in Project view where you want to create your class and then use ⌘N followed by Enter.
I do this a lot, and I don't have an insert key on my laptop, so I made my own keybinding for it. You can do this by opening Settings > IDE Settings > Keymap and navigating to Main menu > File > New... (I would recommend typing "new" into the search box - that will narrow it down considerably).
Then you can add a new keyboard shortcut for it by double clicking on that item and selecting Add Keyboard Shortcut.
Alt-Home until you're in Packages view
Down-arrow until package is highlighted
Alt-insert
Enter X 2
Type name
$PROFIT$
If you use Mac, you are in luck. One can change the keymap for Intellij as Mac OS X, then you can use option+C.
In my (linux mint) system I can not get working combination alt+insert so I do the next steps:
alt+1 (navigate to "tree") --> "context button - analog right mouse click" (between right alt and ctrl) -- then with arrows (up or down) desired choice (create new class or package or ...)
Hope it helps some "mint" owners )).
I also searched this answer. Equivalent of command+N on Mac OS for Windows is ctr + alt + insert which #manyways already answered. If you searching this in settings it is in Settings > IDE Settings > Keymap, Other > New ...
If the difficulty is in finding the option that makes .java or .class files (Like me), then simply,
click on the folder you want to create file on. select new, and type file's name along with extension.
For example, instead of, helloWorld type helloworld.java or any file extension you desire.