This article contains a collection of trips and tricks that are available in Jet Brains‘ IntelliJ Idea to take your productivity at the next level.
Run anything (Ctrl + Ctrl)
Run anything is an universal action that you can use to perform certain tasks much faster. Invoking it is as easy as double-pressing Ctrl.
By default, this shows a list of recently run configurations. But we can also type the name of something to run / search / other run configurations. For example, type in a specific maven goal:
![intellij idea productivity tips](https://www.mastertheboss.com/wp-content/uploads/2022/07/Screenshot-from-2022-07-09-17-29-41.png)
Run Anything supports a large sets of actions, including:
- Run/Debug configurations
- Maven goals or Gradle build
- Open Recent projects (just type “open” to see all recent projects)
- Shell scripts
Find Actions ( Ctrl+Shift+A )
Let’s face it: searching the menus and toolbars in an attempt find out that action you need is an huge waste of time. You can just rely on Find Action command (Ctrl+Shift+A) to quickly locate what you need.
The Find Actions UI will show a list of available actions. Type in the action you’re looking for to learn more. For example, if you want to add Getter and Setter methods to your class, just start typing “getter…” and the Find Actions will suggest all matching actions:
Code Completion (Ctrl + Space)
Every decent editor is able to propose code generation while coding your classes. With IntelliJ code generation is really on steroids. You can use it at different levels (basic / type matching). However, even in its most basic form, just it Ctrl + Space while coding and it will save you lots of time.
For example, you have a variable “greeting”. As you start typing that variable in your code, press Ctrl+ Space. It will automatically propose to add getter/setter methods for it:
Complete Current Statement (Shift+Ctrl+Enter)
Are you sick and tired of writing common instructions such as for/if statement blocks ? Just use Complete Current Statement ! Its most basic usage can just add a semi-colon to the end of the code. But it can do a lot more. For example if you use it while you’re coding a “for” loop, it will add the curly braces and place your cursor inside the block.
Much the same way, in an “if” statement, it can add the parentheses and curly braces and again place your cursor in the correct spot. Even if the IDE does not find anything to finish your statement, it’s useful to use this shortcut to put the cursor where you next need it.
Analyze a Thread dump
Most developers rely on a separate tool to analyze Java thread dumps. Arguably there are plenty of thread dump analyzer tools, some of them featuring a decent level of intelligence.
In general terms, however, Thread Dump analysis requires grouping Threads based on similar stack traces, or status or exceptions. IntelliJ has all you need to give you a clear picture of JVM Threads. This option is available through the Menu Code | Analyze Stack Trace /Thread Dump.
Then, paste in the Thread dump and check the result:
Besides, you can also paste a Stack Trace to have a visual glimpse of the Classes/Methods instead of manually following the files and line numbers.
To learn more about Thread dump analysis check this: How to inspect a Thread Dump like a pro
Project refactoring
Refactoring is a process of improving your source code without creating a new functionality. Refactoring helps you keep your code solid , dry, and easy to maintain. Start by selecting an item to refactor. You can select a file/folder in the Project tool window or expression/symbol in the editor.
Press Ctrl+Alt+Shift+T to open a list of refactorings that can be selected.
The most popular kind of refactoring is the Rename actions which lets you rename, for example, a Class name and update its references. It is also common to rename a single method or a property and apply refactoring on its references.
Besides, did you know that you can apply refactoring also on configuration files ? for example, in Quarkus project (you need Quarkus Idea plugin – Creating Quarkus applications using IntelliJ IDEA ) , you can select an item from the configuration file:
Then, choose Refactor | Rename to change the name of the property from “greeting” to “message”. You will see that, wherever you inject the greeting variable in your code now it is renamed to “message”.
@ConfigProperty(name = "message") String greeting;
Generate dependencies (Alt+ Ins)
Are you adding your project dependencies manually from your pom.xml, after searching through the Maven repository? or are you searching across internet which JAR contains a Class name? There are better alternatives. Simply use this awesome shortcut from your project file (e.g. pom.xml): Alt+ Ins. There, you can choose to Generate some stuff :
The most common option is to Generate a Dependency. You will be able to search for a Maven artifact GAV:
From the Search For Class Tab you can also search for a particular Class. For example, where’s the CircuitBreaker Class?
Code inspection
In IntelliJ IDEA, there is a set of code inspections that detect and suggest fixes in your code before running it. For example, IntelliJ idea can find and highlight various problems, locate dead code, find potential bugs, spelling issues, and improve the overall code quality.
Inspections can scan your code in all project files or only in specific scopes. To run a scan from the menu, select Code | Inspect Code. Next, specify the scope of your code inspection, for example a whole project or a single file. finally, check the list of suggestions in the Inspect window:
It is a good practice to run a periodic assessment of your code. To do that, you can run the code inspection from the command line and store the results as an XML, JSON, or plain text file with a report. Here is the command line that you can place, for example, in a cron job:
idea64 inspect <project> <inspection-profile> <output> [<options>]
Quickly change the JDK for your project
Probably the most common question when you are developing Java with an IDE is how to change the default JDK for your projects. Looks no futher, this option is available in File | Project Structure. As an alternative, from the Find Actions UI, just type “project” and you will see the Project Structure as first option.
Use IntelliJ as editor for Markdown and Asciidoc documents
AsciiDoc is gaining more and more popularity as tool to produce project documents and wikis. Besides markup documents, you can also edite asciidoc files within IntelliJ idea. To do that, just install the asciidoc plugin.
To do that, use the plugin browser (Preferences -> Plugins -> Browse repositories) and type asciidoc in the search. Besides, you can also open a file with an extension recognised by the AsciiDoc plugin (.adoc, .asciidoc and .ad). This will trigger an info message by IntelliJ informing you that there’s a plugin to handle these filetypes.
Conclusion
This article was a walk through the 10 most widely used short cuts in IntelliJ Idea to leverage its powerful features.