Features IntelliJ IntelliJ IDEA

Run IDE Features From the Terminal

IntelliJ IDEA integrates with many different tools used for software development. Most of these tools run in the system shell under the hood. Sometimes you don’t even realize that instead of running a command in the integrated terminal and reading console output, you can use the relevant IDE feature, like a tool window or a dialog that implements this functionality.

For example, the diff viewer actually runs the diff command in the system shell to produce results. Another example is the Log tab in the Git tool window, which is based on the output of the git log command.

If you didn’t know such features existed in IntelliJ IDEA or you are just used to running them in the terminal, now the IDE will let you know you can view the results in the GUI. This increases the discoverability of features and provides a handy way to open your favorite IntelliJ IDEA tools from the terminal.

Here is how it works:

  1. Type a supported command in the terminal and notice how it gets highlighted.
  2. Instead of pressing Enter, which runs the command in the terminal, press Ctrl + Enter or Cmd + Enter to open the corresponding GUI tool. In the example above, it will open the Log tab of the Git tool window and filter commits by authors with “dmitry” in their usernames.

In a similar manner, you can type the diff command with the names of files you want to compare, and when it is highlighted, press Ctrl + Enter or Cmd + Enter to open the diff viewer instead of printing the diff output to the terminal.

This feature also works with most of the commands recognized by Run Anything (press Ctrl twice), such as mvn, gradle, rake, rails, and so on, depending on what plugins you have installed. Try out the commands that you use frequently and see if this feature helps you be more productive.

Try Ctrl + Shift + Enter or Cmd + Shift + Enter to run the highlighted commands in debug mode (use the Debug tool window instead of Run).

You can use the API provided to implement support for more commands and tools. For implementation examples, see the GitLogTerminalCustomCommandHandler and TerminalShellCommandHandler classes in the source code of IntelliJ IDEA Community Edition.

If you want to disable this feature, click the gear icon in the Terminal tool window and clear the Run commands using IDE option.

If you want to change the default shortcuts, open the Settings / Preferences dialog, go to Keymap, then expand Plug-ins | Terminal and modify the following actions:

  • Run highlighted command using IDE (default shortcut: Ctrl + Enter or Cmd + Enter)
  • Debug highlighted command using IDE (default shortcut: Ctrl + Shift + Enter or Cmd + Shift + Enter)

You can try this feature in the latest IntelliJ IDEA 2020.2 EAP.

Happy developing!

image description