IntelliJ IDEA for beginners
- Why
- Download and Installation
- General / basic settings
- Useful plugins
- Navigating the IDE
- Navigating the code
- Other important shortcuts
- Running stuff
- Summary
Switching your favorite editor or IDE after years is not so easy - but doable. For example switching from Eclipse IDE to IntelliJ IDEA. To help you getting started, I’ve collected some subjective tips and tricks.
Why
First of all: Why should you switch? For me, there are two main reasons: In professional live, I’m most likely going to use IntelliJ IDEA more often. So it makes sense to learn how to use it (“know your tools…”). The second reason is: Kotlin support. Since in PMD we use at some occasions (unit tests for now only) Kotlin, it was always a struggle to change these tests within Eclipse. There is a Eclipse plugin for Kotlin support, but it doesn’t really work. Since IntelliJ IDEA is developed by the same company that develops Kotlin - namely JetBrains - the support for Kotlin in IntelliJ IDEA is the best.
There is also another point, which doesn’t prevent me from using IntelliJ IDEA: At least the community edition is open source. If something doesn’t work as expected, I can dig into to code and learn how it works or why it doesn’t. As an open source developer you could also apply for the Ultimate Edition for free. The code of the community edition is on github: https://github.com/JetBrains/intellij-community.
Download and Installation
You can download IntelliJ IDEA from https://www.jetbrains.com/idea/. However, there is also the Toolbox App which is a smallish Java app, that helps you managing your (JetBrains) IDEs. E.g. it allows you to simply install or update the IDE as needed and it provides shortcuts to open (recent or favorite) projects. I open IntelliJ IDEA only through the Toolbox App.
Since the Toolbox App shows a small icon in the system tray, it makes sense to install Tray Icons Reloaded in case you are using the Gnome Desktop. Or you can use Ubuntu AppIndicators, which also shows the tray icons.
IntelliJ IDEA ships its own Java VM (jbr - JetBrains Runtime). The Toolbox App installs your IDEs into
~/.local/share/JetBrains
. It will keep old versions when installing a new version, so that you could go back,
if anything doesn’t work. You can disable this feature in the settings to save some disk space.
General / basic settings
Dark Mode
In order to protect your eyes from today’s very bright monitors, most applications today offer a dark mode or dark theme. So does IntelliJ IDEA. Here the dark theme is called Darcula.
Open the settings (Ctrl + Alt + S) and select the theme under “Appearance & Behavior > Appearance”.
Font size
In case you share your screen or demo something, it might make sense to increase the font size. Open the settings (Ctrl + Alt + S) and select “Use custom font” under “Appearance & Behavior > Appearance”.
Otherwise the font size is probably ok and you don’t need to change it.
Editor settings
There are many settings available under the category “Editor”. Open the settings (Ctrl + Alt + S) and select “Editor”.
Here are some settings you might want to enable:
- “General > Appearance”: “Show method separators”. This draws a thin horizontal line between methods, helping to see, when a method starts and end.
- “General > Appearance”: “Show whitespaces” - this is self-explanatory.
- “General > Code Folding”: Here you can control, which part of the source file should be folded by default. Usually the start of the file (“File header”, “Imports”) are uninteresting: The file header often just contains the license information and the imports are mostly automatically managed by the IDE anyway.
- “General > Smart Keys”: Use “CamelHumps” words. When you double-click a text to select it, normally the text
surrounded by whitespace will be selected. With this “camel humps” setting, the text is split into separate
words at uppercase/lowercase boundary. E.g. if you have
HashMap
and you double-click on “Map”, only “Map” will be selected. This behavior is also active when going to the previous or next word with Ctrl + Left or Right. It’s also honored when selected the current word where the cursor is via Ctrl + W (Extend Selection).
Useful plugins
Like all IDEs IntelliJ IDEA can also be extended with plugins. There are two plugins very useful to learn keyboard shortcuts. Keyboard shortcuts are important, since it is the fastest way to control your IDE and IDEA is designed to be controlled by keyboard. Almost everything can be done by keyboard and you don’t need to switch to your mouse - you can often keep both hands at your keyboard.
In order to search and install plugins, open the Settings (Ctrl + Alt + S) and navigate to “Plugins”. Then under “Marketplace” you can search for plugins and install them.
The two plugins are:
-
“Key Promoter X”: This is a small plugin that shows a small notification with the keyboard shortcut whenever you executed an action in IDEA with your mouse. That way you can see and learn over time the shortcuts. It also counts how often you missed using the shortcut.
Learn more about this plugin on the plugin homepage: Key Promoter X.
-
“Presentation Assistant”: This plugin is useful if you do a demo or simply share your screen with a co-worker. Whenever you execute an action in IDEA (either using your mouse or using a shortcut), this plugins shows a little toast with the name of the currently executed action (including the shortcut). That way anybody can comprehend what you were doing in the IDE. As the action names are shown, it also helps to reinforce the shortcuts if you are a visual learner.
Learn more about this plugin on the plugin homepage: Presentation Assistant.
Note: IntelliJ IDEA also has a “Presentation Mode”, which increases the font size etc. You can enter this mode via the menu “View > Appearance > Enter Presentation Mode”. After that, the menu is hidden but appears when the mouse cursor moves to the top of the window. You can leave the presentation mode again via the same menu.
Navigating the IDE
IntelliJ IDEA’s window consists of a couple a building blocks. Clearly there is the main part, the editor, in the middle. This usually takes the most space. Then there are several so-called “tool windows” surrounding this editor, which can be shown or hidden. These tool windows can be compared to the views in Eclipse. However, in IntelliJ IDEA there is nothing like a perspective, there is always one layout.
The most important tool windows on the left are:
- “Project” - which is similar to the “Project Explorer” in Eclipse.
- “Structure” - which is like the Outline view in Eclipse.
These tool windows can be opened also with keyboard shortcuts, e.g. Alt + 1 opens the project window. And Alt + 7 opens the structure window.
Important tool windows at the bottom are:
- “Terminal” - self-explanatory (Alt + F12).
- “Git” - displays the git history (Alt + 9).
Tool windows at the right:
- “Maven” - this is only there if you are working on a maven project. Otherwise there would be e.g. Gradle. There is no shortcut, but I don’t use this window very often. You can reimport the projects if necessary from there or browse the dependencies.
When you opened a tool window or switched to a tool window, then the keyboard focus will be in that tool window. E.g. with Alt + F12 you switch to the terminal. Then you can type in a command and execute. Now, if you press Esc, you can switch back to the main editor. The tool window stays open. If you want to hide the tool window, then use Shift + Esc instead.
Navigating the code
There is one more setting which is very useful: Open the project tool window (Alt + 1). Then (with your mouse) click the gear icon on the top and select the two options “Open Files with Single Click” and “Always select Opened File”. This makes it fast to open the files from the project window. And since you can have multiple files opened in the editor in tabs, if you switch the editor tabs, the corresponding file will be selected in the project tool window. That way e.g. you can easily open “sibling” files in the same directory.
Now on to some basic navigating tasks:
- In the project window, you can use your cursor keys Up and Down to select a file. When you hit Enter you switch to the editor and can start modifying the file right away.
- Often (maybe always) it is easier to just search: Hitting Shift + Shift (“Double-Shift”) shows a small search dialog where you can enter e.g. the name of the class you want to edit. This is similar to “Open Type…” (Ctlr+Shift+T) in Eclipse.
- In the editor, you can then Ctlr+Click on any element to navigate to it. Or you can use a keyboard shortcut: Ctlr + B. (Eclipse: F3 - “Open Declaration”)
- In the editor, you can navigate to a specific method with Ctlr + F12 (Eclipse: Ctrl+O - “Open Outline”).
- Navigating back: Alt + Shift + Left. Note: This shortcut might be different depending on your desktop environment. E.g. the original shortcut clashes with Gnome’s “move window to left screen”.
- Switching between editor tabs: Simply use Alt + Left or Alt + Right.
Other important shortcuts
There are of course many, many short cuts, but here are some important:
-
We have already seen the double-shift shortcut: Shift + Shift. This is a very universal tool - it can search everything. Just try it. You can search for your types or files or methods or …
You can also search for UI actions: If you don’t know where this action is in the menu or you don’t know the exact name of the action, you can also search for it. E.g. you can search for “Save As”.
- If you hit double-double-shift (4 times Shift) or hit double-shift again while the search dialog is open, it checks the option “Include non-project items”. That way, you can also search for methods in libraries in the project’s dependencies.
-
Another shortcut, that can do anything like magic is: Alt + Enter. Use it while you are in the editor. It will suggest fixes or refactorings. It is similar to Eclipse’s quick fix option. E.g. it is very easy that way to introduce a local variable.
-
Refactorings
- Ctlr + Alt + V: Extract local variable
- Ctrl + Alt + C: Extract constant
- Ctrl + Alt + M: Extract method
- Shift + F6: Rename
-
Editing
- Ctlr + W: Expand selection. Repeat the shortcut multiple times to select more and more: The single word, the whole word, the whole line, the whole code block, the whole method, the whole class, the whole file.
- Ctlr + Shift + Up/Down: Move line/block up or down
- Ctrl + Y: Delete a line
- Ctrl + D: Duplicate a line (not be confused with the same shortcut in Eclipse which deletes a line).
-
Alt + Shift + Ins: Enter column selection mode by keyboard. You can do the same via mouse selection by holding down Ctlr + Alt + Shift and then drag the selection with the mouse.
Leave this column selection mode by using the same shortcut again.
-
There are also live templates. E.g. entering
sout
and selecting the item will create aSystem.out.println()
statement. There are more templates, likesoutv
to print a local variable orsoutm
to print the current class+method names for debugging.soutp
would create a print statement to output the parameters of the current method.There are many more templates. You can see the available templates under Settings (Ctlr + Alt + S) in “Editor > Live Templates”. You can even define your own templates.
-
Optimize imports: Ctlr + Alt + O.
-
Eventually you want to commit you changes. Ctlr+K will prepare a commit with selecting all changes by default. It git speaking, it will select all changes for staging.
-
IntelliJ IDEA ships a massive number of code inspections. Some of them are also executed before committing (depending on your active inspection profile). You can also run the inspections manually by right-clicking on a project/folder selecting “Analyze > Inspect Code…”. By keyboard, you could start this action by searching for it with the double-shift shortcut.
Running stuff
When you are writing a unit test you probably want to execute it as well. With Ctlr + Shift + F10 the current unit test will be executed. If your cursor (the context) is in a test method, only this test will be executed, otherwise all tests in the class.
When you switched to another file to fix something and want to execute the test again, just use Shift + F10 to repeat the last run.
The same shortcuts work for debugging with F9 instead of F10, but I usually switch to the mouse then.
Summary
There are many shortcuts which can be overwhelming at first. But you don’t need to know everything from the start. Keep using a few and from time to time expand your knowledge. IntelliJ IDEA also provides the ability to print a keymap with the important shortcuts (menu “Help > Keyboard Shortcuts PDF”).
There is also the possibility to configure your own shortcuts (e.g. to have the same shortcuts like in Eclipse). However, I decided not to do this, because if you need to switch your workstation for whatever reason, you’d had a hard time again. So I’ll stick to the defaults. Then switching IDEs becomes similar to switching musical instruments…
Comments
No comments yet.Leave a comment
Your email address will not be published. Required fields are marked *. All comments are held for moderation to avoid spam and abuse.