- Terminal
- Open the Terminal tool window
- Start a new session
- Configure the terminal emulator
- Run IDE features from the terminal
- Open the Log tab of the Git tool window from the terminal
- Terminal
- Using the Terminal in IntelliJ IDEA
- Opening the IntelliJ IDEA Terminal Window
- Multiple Terminal Sessions
- Naming Terminal Tabs
- Pasting Code from the Editor into the Terminal
- Terminal Locations from the Command Window
- URLs and Stack Traces in the Terminal Window
- Run IDE Features from the Terminal
- Summary
- How to open two terminal windows in IntelliJ IDEA, PyCharm?
- 9 Answers 9
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.
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 information about changing the shell, see Configure the terminal emulator.
Open the Terminal tool window
Select View | Tool Windows | Terminal from the main menu or press Alt+F12 .
By default, the terminal emulator runs with the current directory set to the root directory of the current project. You can change the default start directory in Settings/Preferences ( Ctrl+Alt+S ) | Tools | Terminal .
Alternatively, you can right-click any file (for example, in the Project tool window or any open tab) and select Open in Terminal from the context menu to open the Terminal tool window with a new session in the directory of that file.
Start a new session
Click on the toolbar to start a new session in a separate tab.
To run multiple sessions inside a tab, right-click the tab and select Split Vertically or Split Horizontally 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 on the Terminal toolbar or right-click the tab and select Close Tab from the context menu.
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 rename a 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.
Configure the terminal emulator
In the Settings/Preferences dialog Ctrl+Alt+S , select Tools | Terminal .
Specify the desired shell to use with the embedded terminal emulator, change the start directory, and define environment variables among other settings.
IntelliJ IDEA should automatically detect the default shell based on your environment. Here are some of the possible shells you might consider:
Bash for Windows: bash.exe
Command Prompt: cmd.exe
Cygwin: «C:\cygwin\bin\bash.exe» —login -i
The embedded terminal emulator also inherits the following IDE settings:
On the Keymap page, you can configure the copy Ctrl+C and paste Ctrl+V shortcuts.
On the Editor | General | Appearance page, you can configure blinking frequency for the caret. The Terminal does not inherit the Use block caret option because it always renders the caret as a block.
On the Editor | Color Scheme | Console Font page, you can configure line spacing and fonts.
On the Editor | Color Scheme | Console Colors page, you can configure font colors.
On the Editor | Color Scheme | General page, you can configure the selection foreground and background colors.
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, 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.
Open the Log tab of the Git tool window from the terminal
Type a supported command in the terminal and notice how it gets highlighted.
Instead of pressing Enter , which runs the command in the terminal, press Ctrl+Enter to open the corresponding GUI element. In this example, it will open the Log tab of the Git tool window and filter commits by authors with “dmitry” in their usernames.
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. To run a highlighted command in debug mode (use the Debug tool window instead of Run ) press Ctrl+Shift+Enter .
If you want to disable this feature, click on the title bar of the Terminal window and clear the Run Commands using IDE option.
Terminal
Use this page to customize the Terminal Alt+F12 settings.
IntelliJ IDEA implements the functionality with a bundled plugin, which can be completely disabled by clearing the checkbox on the the Plugins page of the Settings/Preferences Ctrl+Alt+S .
Specify the shell that will run by default. Here are some examples of different shells:
Bash for Windows: bash.exe
Command Prompt: cmd.exe
Cygwin: «C:\cygwin\bin\bash.exe» —login -i
Integrate the terminal with the system shell to properly keep track of your command history for sessions and load a custom config file with required environment variables.
Shell integration works for sh , bash , zsh , and fish shells.
Detect and highlight commands that can be used as IDE features instead of running them in the terminal and reading console output.
When enabled, instead of pressing Enter , which runs the command in the terminal, press Ctrl+Enter to open the corresponding GUI element. See Run IDE features from the terminal for details.
For the Python interpreter being a virtual environment, with this checkbox selected, the virtual environment is automatically activated ( activate is performed automatically).
This option is available only if you have the Python plugin installed.
Using the Terminal in IntelliJ IDEA
In this video we’re going to take a look at IntelliJ IDEA’s built in terminal. This performs the same function as your operating system’s terminal or command feature, but using the terminal inside IntelliJ IDEA has a number of benefits.
Opening the IntelliJ IDEA Terminal Window
In this example we have a simple Spring Boot application that needs a running MongoDB database. We can open the terminal window with ⌥F12 on macOS, or Alt+F12 on Windows and Linux. The terminal supports all the same commands that the operating system supports.
If we want to start the MongoDB database instance with a specific path for storing the data, we can type:
and press enter. When MongoDB is running in the terminal session, we can go back to writing the application code in the editor. By using the built in terminal, we don’t have to switch between applications, and we can easily have all aspects of our development right in front of us in the same window.
Multiple Terminal Sessions
We can open a second terminal tab with ⌘T on macOS, or Ctrl+Shift+T on Windows and Linux, to run the MongoDB shell as a new command:
Then we can interact with the server that’s running, and check everything is OK for our application.
Running commands in different tabs is helpful, but sometimes two different processes are closely related and we want to see them together. For this, we can split our terminal window so that we can run two in the same window. For example, you can open up the mongo shell in this split window and can see if the commands have any impact on the running server.
Naming Terminal Tabs
We can run any type of command from the terminal window. For example, although IntelliJ IDEA has full integration with Gradle, sometimes we might want to check a build tool like Gradle or Maven runs correctly from the command line. We might sometimes do this with different Java versions or different arguments to those we’re using in the application. Given that we might be using a number of terminal sessions with a number of different processes or parameters, it’s useful to rename the tabs to something helpful. You can do this from the context menu, which you can open by right-clicking on the tab. That way we can easily reopen the one we’re interested in.
We can move between the different tabs with ⌘⇧[ or ⌘⇧] on macOS or Alt+← or Alt+→ on Windows and Linux. We can switch between the splits with ⌥⇥ on macOS, or Ctrl+Tab on Windows and Linux. We can close splits or tabs with ⌘W on macOS, or Ctrl+F4 for Windows and Linux.
When we restart IntelliJ IDEA, our terminal session names and other settings will persist.
Pasting Code from the Editor into the Terminal
Running command line processes from inside IntelliJ IDEA is useful for keeping us in the same context while we’re developing, and for sharing content between different parts of our application. For example, if we’re running the Java REPL JShell in an IntelliJ IDEA terminal window, it’s easy to copy code from the editor and paste it into JShell. This is not specific to running JShell in the terminal, it’s easy to copy and paste code from anywhere in IntelliJ IDEA into the terminal window.
View steps in video
Terminal Locations from the Command Window
The integration provided by the IDE also extends to being able to open a location from inside the project window in the terminal window from the context menu. Right click on an item in the Project Window, for example, and select «Open in Terminal». This means that we can have a terminal window in the correct location immediately without having to navigate using the command line.
URLs and Stack Traces in the Terminal Window
URLs in the terminal window are clickable, so we can click on any link shown in the terminal window to open them in the browser. File names in the terminal can also link back to the file in the project. In stack traces, you can click on the file name and IntelliJ IDEA will open the file and put the caret on the line that caused the problem. This takes some of the pain out of debugging problems.
Run IDE Features from the Terminal
You may notice that some commands in the terminal window are highlighted. This is a new feature in IntelliJ IDEA 2020.2 that shows that the command could be run in the IDE, meaning we don’t need to use the command line.
If it’s highlighted in yellow and we press Enter, the command will be run in the terminal window just as we’d expect. If we type the same command again, but this time use ⌘⏎ on macOS, or Ctrl+Enter on Windows and Linux, IntelliJ IDEA will use the feature in IntelliJ IDEA and open the relevant tool window.
IntelliJ IDEA detects a number of different commands that could be run in the IDE instead of from the command line. For example, the git command:
will execute normally if we press Enter. If we press ⌘⏎ on macOS, or Ctrl+Enter on Windows and Linux, it opens the Git log window in IntelliJ IDEA.
This is a great way to discover features in the IDE that are an alternative approach to using the command line. If we decide we’re not going to need these suggestions, we can turn off «Run IDE Features from the Terminal» from the terminal window’s settings using the context menu. The commands will no longer be highlighted.
Summary
IntelliJ IDEA’s terminal window is a powerful and helpful tool for developers. It keeps our attention in the same tools which reduces context switching. It makes it easy for us to share things between the editor and the command line. The terminal is integrated allowing us to easily move from the project code to the terminal and back again, and it also can show us alternative ways of doing the same thing, using the IDE’s version of the command line tool.
How to open two terminal windows in IntelliJ IDEA, PyCharm?
Is it possible to open two terminal windows in IntelliJ IDEA (or in any other IDE based on it, like PyCharm)?
9 Answers 9
In case of terminal toolbar status, you can do one of these options
Also after that you can drag them as tabs and let them be side by side.
You can open multiple tabs and then use the mouse drag them out into the editor area. Then you may want to split the editor vertically to have two consoles side by side. Or you could use one terminal in the tool window and the other up in the editor area.
Besides the great answer given by avb (using the + or right click), you can of course also use a hotkey for this (when selected the terminal) press:
MacOs: Command+T / ⌘T
Windows / Linux: Ctrl + T
Note: you can even rename tabs by double clicking on their label.
You can drag terminal tabs into editor view and then use standard horizontal/vertical split to position them wherever you want them.
It’s a bit hack since the editor then considers your terminal window a file and names it Local or Local(x) if you have multiple.
Also note, that since IDE considers it a file, you cannot just split the view to get a new instance of terminal. You would have to use the terminal view to create a new tab and then again drag it to the designated area.
This is how it looks: