IntelliJ IDEA tips - mhulse/mhulse.github.io GitHub Wiki
See also: macOS Java Android dev setup (Android Studio, Intellij Community Edition, etc.)
In Preferences > Editor > General > Appearance, check the Show method separators box.
Change the separator color: See Preferences > Editor > Color Scheme > General > Code > Method separator color > Foreground
Auto-generated files:
Preferences > Appearance & Behavior > File Colors
Ignored by VCS (e.g. .gitignore
excluded files):
Test directory and files:
I recommend using the JetBrians Toolbox App to manage your JetBrains apps (like IntelliJ IDEA).
If not already using, you have to uninstall your existing version, and then install the toolbox. From there, you can choose JetBrains apps to install.
There’s also a project management tab, which makes it easy to open and switch between projects.
F4 contextual über jump to source (found under View menu)
CTRL + H for class hierarchy
COMMAND + SHIFT + A (search for hierarchy)
COMMAND + OPTION + arrow keys (square brackets may work too) to jump back and forth
Hold OPTION to insert cursor in multiple spots
When auto completing, hit TAB rather than ENTER (tab will replace rather than add)
OPTION + ENTER for contextual options based selected context
Preferences + Code Style + General > Visual Guides
I use the value 36,72,144
, which is based on Python’s PEP 8 style guide’s “Maximum Line Length”
CMD + E
CMD + OPTION + LEFT or RIGHT
You’ll have to remove the default CMD + UP and CMD + DOWN shortcuts.
See: Odd command + up arrow hotkey change
Note that by changing this mapped key, it will remove the existing (annoying) map of minimizing window to dock.
Make your selection and then: CMD + M
Specifically, files:
SHIFT + CMD + O
Files and folders:
Hit SHIFT twice and search for file or folder by typing its name.
Find:
SHIFT + CMD + F
Find and replace:
SHIFT + CMD + R
This is like Atom or VS Code’s “Command Palette”:
CMD + SHIFT + A
Bonus! If you’re on a Mac, disable these system shortcuts:
If your Jetty/other server doesn’t shut down properly, and you run into conflicting ports, then run lsof -i:<port number>
; once process is found, use kill -9 <process id>
Option + Enter for contextual options based selected context
CTRL + G or CTRL + CMD + G to multi-select
Hold down COMMAND to make whatever you’re hovering over clickable (if it’s a class, you can click to jump to that definition).
Copy class smartly using contextual menu and it will refactor the copied code contextually
OPTION + COMMAND + LEFT ARROW OR RIGHT ARROW
If zsh has been installed via Homebrew: /usr/local/bin/zsh
If you don’t have an .editorconfig
setup (see below) you might want to adjust these whitespace display/settings:
When you open a file, reveal it in the sidebar too.
Alternatively, you can use: Navigate >
Select in... >
Project View
Enable this option via the File menu; login using your JetBrains account.
Note that you will have to select this option to login, and then select it again to enable it.
Install Fira Code on your system.
-
IDE Settings
>
Editor>
Font
-
IDE Settings
>
Editor>
General>
Smart Keys>
Surround selection on typing quote or brace
View -> Tool Windows -> Gradle
Note: Click the refresh icon in this tool window if you get a message like:
Warning: Unable to make the module: ap-site.main, related gradle configuration was not found. Please, re-import the Gradle project and try again.
This should be enabled by default:
Put a file named .editorconfig
at the root of your project:
# This file is for unifying the coding style for different editors and IDEs.
# EditorConfig is AweSome: http://editorconfig.org/
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_size = 4
indent_style = space
Here’s a more complex example: @mhulse / gh-boiler / .editorconfig
File > Settings > Editor > Code Style > Java > Code Generation
If not done so already, go to View
menu and choose Toolbar
When you use “Import Project”, you are presented with a series of dialogs to set various options (for both Gradle and the project). Using “Open”, you do not get those dialogs as IDEA will use defaults (of which, you can manually change later).
I now prefer using an Application
configuration vs. Gradle
as it’s way faster! See “Application” vs. “Gradle” configurations for more info.
-
From the Welcome window, choose “Import Project”.
-
In the Finder window, navigate to your project’s root and click “Open”.
-
From the “Import Project” window, choose “Import project from external model” and choose Gradle (see docs).
-
Choose “Use gradle 'wrapper' task configuration”
You can also specify how to group modules in your project. For example, if you want to sort out your modules and group them by their qualified names, use the using qualified names option. In this case when module groups are generated using Gradle group, the prefixes in module names are also accounted for.
(See: Creating a new Gradle project)IntelliJ IDEA allows you to logically group modules. If you have a large project with multiple modules, grouping will make it easier to navigate through your project.
(See: Group modules)
Next, IDEA will process your new project and open the IDE window.
Q: What’s the difference between IntelliJ IDEA “Application” or “Gradle” configurations?
A: IntelliJ IDEA can either build and run the project itself or delegate these actions to Gradle. In some cases the project will build and run properly only with the delegation (in case of some complex configuration of your build scripts that IntelliJ IDEA doesn't understand and cannot convert to its internal build and run actions). So, it's up to you which way to use.
Gradle Goodness: Delegate Build And Run Actions To Gradle In IntelliJ IDEA
-
Click “Add Configuration”
-
From the “Run/Debug Configurations” window, click the “Add New Configuration” plus icon in the top left of window; choose “Application”:
-
Fill out the configuration like so:
Note: Make sure your Gradle
clean
task is ran before thebuild
!In older versions of IntelliJ, Make sure to click “Single instance only” (looks like this is now the default in newer versions of IntelliJ):
Click “Share” too, if you want to include this config via git:
The best way to share IntelliJ Run/Debug configurations between projects is to use the “Share” checkmark. The share check-mark pulls the setting out of your
workspace.xml
and instead puts it in the directory.idea\runConfigurations
. This is designed so you can share the setting with others. You could copy this file and put it in the same location in all your idea projects. -
Click “Apply” and “OK”.
-
Now you can run the project using the green “debug” or “run” icons:
-
From the “Run/Debug Configurations” window, click the “Add New Configuration” plus icon in the top left of window; choose “Gradle”:
-
Fill out the configuration like so:
Make sure to click “Single instance only”:
Click “Share” too, if you want to include this config via git:
-
Click “Apply” and “OK”.
-
Now you can run the project using the green “debug” or “run” icons: