IntelliJ IDEA 2024.3 Help

Terminal

IntelliJ IDEA includes an embedded terminal emulator for working with your command-line shell from inside the IDE. Use it to run Java tools, Git commands, set file permissions, and perform other command-line tasks without switching to a dedicated terminal application.

Enable the Terminal plugin

This functionality relies on the Terminal plugin, which is bundled and enabled in IntelliJ IDEA by default. If the relevant features are not available, make sure that you did not disable the plugin.

  1. Press Ctrl+Alt+S to open settings and then select Plugins.

  2. Open the Installed tab, find the Terminal plugin, and select the checkbox next to the plugin name.

Initially, the terminal emulator runs with your default system shell, but it supports many other shells, such as Windows PowerShell, Command Prompt cmd.exe, sh, bash, zsh, csh, and so on. For more information about changing the shell, refer to Terminal settings.

Open the Terminal tool window

  • Go to View | Tool Windows | Terminal or press Alt+F12.

    By default, the terminal emulator runs with the current directory set to the root directory of the current project. For more information about changing the default start directory, refer to Terminal settings.

  • Right-click any file (for example, in the Project tool window or any open editor tab) and select Open in | Terminal to open the Terminal tool window with a new session in the directory of that file.

Start a new local session

  • To start a new session in a separate tab, click the Add button on the toolbar or press Ctrl+Shift+T.

    New session in the terminal

To run multiple sessions inside a tab, right-click the tab and select Split Right or Split Down in the context menu.

The Terminal saves tabs and sessions when you close the project or IntelliJ IDEA. It preserves tab names, the current working directory, and even the shell history.

To close a tab, click the Close button on the Terminal toolbar or press Ctrl+F4.

Press Alt+Right and Alt+Left to switch between active tabs. Alternatively, you can press Alt+Down to see the list of all terminal tabs.

To clear the terminal screen, press Ctrl+L.

Start a new SSH session

  1. On the toolbar, click Start a new SSH session and select New SSH Session.

  2. Enter the address of the host to which you want to connect, and provide authentication data.

    Providing data in the SSH Session dialog

    Or, if you have configured SSH configurations, you can select one of them from the list.

Start a new SSH session

To terminate the connection, click Terminate session in the terminal tab.

Rename terminal tab

  • Right-click the tab and select Rename Session from the context menu.

  • To search for a certain string in a terminal session, press Ctrl+F. This searches all text in the session: the prompt, commands, and output.

By default, the search is not case-sensitive. You can click the Match Case icon Match case in the search field to make it case-sensitive.

Configure the terminal emulator

  • Press Ctrl+Alt+S to open settings and then select Tools | Terminal.

  • Alternatively, click on the Terminal toolbar and select Settings.

For more information, refer to Terminal settings.

Run IDE features from the terminal

Instead of running a specific 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, you can launch a gradle or mvn command from the Terminal tool window and view its output in the Run or Debug tool window.

Enable running IntelliJ IDEA commands from the Terminal

  1. Open the Settings dialog (Ctrl+Alt+S) and go to Tools | Terminal.

  2. Select the Run Commands using IDE checkbox.

Run a command in the Run or Debug tool window from the terminal

  1. Type a command in the terminal and notice how it is highlighted.

    Smart command execution highlighting for Gradle command in the Terminal
  2. Instead of pressing Enter, which runs the command in the terminal, press Ctrl+Enter to open the corresponding GUI element.

    To run the command in the Debug tool window, press Ctrl+Shift+Enter.

This feature also works with most of the commands recognized by Run Anything (press Ctrl twice), for example npm or rails depending on what plugins you have installed. To run a highlighted command in debug mode (use the Debug tool window instead of Run) press Ctrl+Shift+Enter.

New Terminal

Starting with the 2024.1 release, a beta version of the new terminal is available in IntelliJ IDEA.

Along with its improved look and feel aligned with the new UI, other major features include:

  • Separation of command output into distinct visual blocks. Press Ctrl+Up to navigate to the output area and Ctrl+Down to switch to the input area. Use the Up and Down arrow keys to navigate the output area blocks.

  • Command completion, including completion for command names, arguments, flags, and paths. For each suggested value, the new terminal displays quick documentation.

    New Terminal tool window

    Completion for command names and arguments is available as you type them, but you can also press Ctrl+Space or Tab after a command name to get the list of possible arguments.

    To display the history of commands that you have previously entered, press Up in the input area.

Enable New Terminal

  1. Open the Terminal tool window: View | Tool Windows | Terminal.

  2. In the tool window header, click Options and select Enable New Terminal.

Enable New Terminal

Alternatively, open the IDE settings (Ctrl+Alt+S) and go to Tools | Terminal | Enable New Terminal.

Search in output blocks

While the full text buffer remains searchable, the new terminal also enables searching within specific output blocks.

  1. In the Terminal tool window, press Ctrl+F.

  2. In the search dialog than opens, click Search in blocks (Search in block) and type the keyword you are looking for.

This narrows the search to only the output block that is currently selected. You can click any block to select it or use the Up and Down arrow keys to navigate them.

Search in New Terminal

Configure prompt style

By default, IntelliJ IDEA shows the terminal prompt on two lines with the input below the prompt. You can customize it to apply the single-line style or use the prompt settings from your shell.

  1. Open the IDE settings (Ctrl+Alt+S) and go to Tools | Terminal.

  2. In the Prompt style list, select one of the following:

    • IDE single-line prompt: show the input at the same line as the prompt.

    • IDE double-line prompt: show the input below the prompt (default behavior).

    • Shell prompt (PS1): use the prompt style configured in your shell.

Alternatively, right-click the prompt in the Terminal tool window and select a prompt style.

Configure prompt style

Use AI Assistant to generate terminal commands

  1. In the Terminal tool window, click (Ask AI Assistant) or press Ctrl+\.

  2. Type your query and press Enter.

    AI Assistant will generate a command taking into account the shell that you are using and your terminal context, such as the name of the current directory and the output of the previous commands.

  3. Press Enter again to run this command.

AI Assistant in Terminal
Last modified: 11 November 2024