IntelliJ IDEA
IntelliJ IDEA – the Leading Java and Kotlin IDE, by JetBrains
One Shortcut to Run Them All
IntelliJ IDEA has a lot of features. While its sophisticated GUI aims to meet all of your development needs, you may need some time and knowledge to find a window or a setting.
What if there was some kind of universal action that you could use to perform certain tasks faster? Today, let’s take a look at a simple but not yet widely-known command, Run Anything, available in IntelliJ IDEA 2018.3+.
Invoking it is as easy as double-pressing Ctrl. What is it used for? It is a shortcut for multiple actions:
- Open recent projects
- Launch run/debug configurations
- Run build tool commands
- Run CLI commands or scripts “in context”
Run Anything is not only faster. It also lets you chain command arguments, define context, browse the list of suggestions, and preview help for some commands. It combines the simplicity of a command line with the flexibility and power of the IntelliJ IDEA GUI.
Let’s embrace the new way of running anything!
Open recent projects
How do you usually open recent projects in IntelliJ IDEA?
You probably go to the main menu, click File | Open Recent and select your project from the list, which can take a while. Can you open it without taking your hands off the keyboard?
A quicker way
With Run Anything, all you have to do is double-press Ctrl and start typing your project name. You’ll instantly see the list of suggestions. Click the name of the project that you want to open. If you can’t remember the name, just type open to view the list of all recent projects.
Launch a run/debug configuration
In IntelliJ IDEA, you can run and debug your app in a number of ways.
If you like to customize your app startup, you may have a bunch of run/debug configurations. When you run it, you have to explicitly select a configuration from the list, which can be time-consuming.
A quicker way
Run Anything can expedite this operation. Just as for opening a project, double-press Ctrl and start typing the name of a run/debug configuration. To debug your app, hold Shift while pressing Enter.
Run build tool commands
This is where Run Anything really shines.
IntelliJ IDEA lets you run build tool commands, such as Maven goals or Gradle tasks, using the dedicated Maven or Gradle tool windows. You can also specify the tool commands in your run configurations. These approaches work well, but they require you to open tool windows or dialogs and use the mouse to navigate to the command you want.
A quicker way
Double-press Ctrl and start typing your tool command, for example, mvn or gradle (it can also be npm or yarn or other tools depending on your IntelliJ IDEA project and enabled plugins). As you type, you’ll see the list of suggestions for command completion.
Here is another trick: with Run Anything, you can easily define the execution context. Let’s say you want to run mvn validate on a particular Maven subproject — simply click Project and select a Maven module.
Not sure about when to use a Gradle task? Need quick help on what a Maven command does? Use Run Anything! It displays help for some external tool commands:
Run CLI commands
Finally, if what you enter is not a build tool command, nor the name of a configuration or a project, Run Anything will run it as a terminal command.
By default, it will be executed in your project root directory, but what if you want to run a simple script that is open in the editor? Enter your command and then hold Option (for macOS) or Alt (for Windows) while pressing Enter. This will “Run in Context”, that is execute your command in the directory the open file is in.
Run Anything has been around for the last three years. Over this time, we have collected your feedback and ideas on how to make it better. If you also have any suggestions, post them in the comment section. In the meantime, we have just released the brand new IntelliJ IDEA 2021.3 that you can try right away by downloading it from our website.
Happy developing!