IntelliJ IDEA Newsletter

10 places you don’t need to use the mouse in IntelliJ IDEA

Read this post in other languages:
Français, 한국어, Türkçe, Deutsch, Русский, 简体中文

When working with IntelliJ IDEA, do you prefer to work with your keyboard over your mouse? If so, you are in for a treat! In this blog post we’ll show you 10 places where you didn’t know you could avoid using the mouse for everyday tasks.


1. Modifying the size of your Project tool window (or other active tool windows)

The Project tool window is one of the most frequently used ones in IntelliJ IDEA. Often you might need to increase or decrease its width. Instead of using your mouse, press Ctrl+Shift+Right (Windows or Linux) or ⇧⌘Right (macOS) to increase the width of the tool window, and Ctrl+Shift+Left or ⇧⌘Left to decrease it (for IntelliJ IDEA 2021.2 and earlier versions).

For other tool windows like Run or Problems, you can increase their height by using Ctrl+Shift+Up (Windows or Linux) or ⇧⌘Up (macOS), and decrease it with Ctrl+Shift+Down or ⇧⌘Down (for IntelliJ IDEA 2021.2 and earlier versions).

For IntelliJ IDEA 2021.2.1 and newer versions, these shortcuts have changed to Ctrl+Alt+Shift+(Right/Left/Up/Down) for Windows and Linux and ⌥⇧⌘+Right/Left/Up/Down for macOS.

2. Use Esc to return to the editor window and F12 to jump to the last tool window

After you are done working with a tool window like the Project tool window, Debug window, Maven, or others, use Esc to return to the editor (instead of using the mouse to click in the editor window).

You can also use F12 to return the focus to the last used tool window (as an alternative to using the specific shortcut for that tool window).

In the following gif, the presentation assistant doesn’t display the text ‘Escape’ when I use the escape key to return the focus to the editor window.

Is pressing Escape (or any other key) context-specific? Yes, it is. Go to Settings -> Keymap -> Find Actions by Shortcut and then press Escape (because you want to know the result of pressing it in different contexts).

3. Show a tool window

Let’s start with how a lot of developers show a tool window in IntelliJ IDEA. For example, to bring up Pull requests, you can click on the Pull requests tab in the tool window bars:

You can skip using the mouse for this, too! Well, we’ll need the mouse for one little thing first, and then we can forget about it.

When you hover over the Pull Requests tab, you will be able to see if a shortcut has been assigned to this tool window. In this case, no shortcut is assigned. Let’s assign one. Use the Find action, search for ‘Pull Requests’ with the description ‘View | Tool window’, and use Alt+Enter to assign a shortcut, for example, Ctrl+Shift+Alt+9.

Now that the shortcut is set, you can use it to show (or hide) your Pull requests tool window.

Alternatively, if a shortcut has already been assigned to the tool window, like Alt+1 for the Project tool window or Alt+7 for the Structure tool window, you’ll see the shortcut when you hover over the tab in the tool window bars.

You can also invoke the Switcher feature in IntelliJ IDEA by using Ctrl+Tab (or ⌃Tab) to view a list of the tool windows and recent files. This feature lets you quickly navigate to the tool window name by using the arrow keys.

If you prefer to work with the menu bar, you can also choose View | Tool windows and view a list of all the available tool windows.

4. Closing an active or all tool windows

There are multiple ways to close or hide a tool window. Use Shift+Escape (or ⇧ Esc) to hide an active tool window. You can use this specific shortcut to hide or show a tool window. For example, Alt+9 (or ⌘9) shows the Git tool window. Pressing Alt+9 (or ⌘9) again hides this tool window.

You can also use the shortcut Ctrl+Shift+F12 (⇧⌘ F12) to hide or restore all of the tool windows.

5. Use Alt+Enter to view the suggestions by the bulb icon

You don’t have to click on the bulb icon to view the suggestions you have for your code snippet anymore! Navigate to the line of code where you see the bulb icon and invoke Context actions using Alt+Enter to view the same suggestions.

6. Declare a new class while working in the code editor window in the required package

This is one of the hidden gems of IntelliJ IDEA. Few developers are aware of it, even though it can be very useful.

To create a class while you are working in the editor, Use Alt+Home (or ⌘ Up) to access the navigation bar. Select the package in which you want to declare the new class, interface, or another entity, and then invoke the new dialog by using Alt+Insert or (⌘ N). Type in the name and you are good to go.

Additional tip: To create a subpackage, add the package name as the prefix. For example, to create the class, say, ‘NewClassInPackageSpace’ in a new subpackage, say, ‘space’, within the package ‘com’, write “space.NewClassInPackageSpace” in the new dialog box.

7. Navigate between open files

Lots of developers use tabs to navigate between their files in the editor, but there are better ways.

i) Use Alt+Right or Alt+Left to quickly navigate between the last files you worked with. However, the presentation assistant doesn’t display the shortcuts used in this case.

This shortcut is useful to navigate between the files you’ve recently worked with because you can move between the files very quickly.

The following gif shows how you can use Alt+Right or Alt+Left to navigate to other files quickly:

ii) Use the Switcher tab (Ctrl+Tab on Windows and Linux, ^Tab on macOS) to view a list of the tool windows and files you’ve worked with recently. Select the tool window or file to open.

iii) Use Ctrl+E (or ⌘E) to view files you’ve worked with recently. This list also includes all the types of files you opened. If you Press Ctrl+E again with the dialog box still open, the list is narrowed to the list of files edited.

iv) If you still can’t remember the file you were working with, access Recent Locations by using Ctrl+Shift+E, which shows you a couple of lines of the file along with the file name. Using the same shortcut again with the dialog box still visible shows the recently edited files.

8. Quick view of source of classes, interfaces, enums, records, methods, variable declarations, etc.

If you’re reading a test you’ve written and you want to quickly view the definition of a method, just place the cursor on the method name and press Ctrl+Shift+I. This way you don’t have to navigate to another class to read the code you’re interested in. You can apply this to view the definition of classes, methods, or any other entities. The name of this feature is Quick Definition

9. Modify the width and height of a dialog window

When you invoke a dialog box, you can modify its height and width by using Ctrl+Shift+Left/Right/Up/Down (Windows or Linux) or ⇧⌘Left / Right / Up / Down (MacOS) for IntelliJ IDEA 2021.2 and earlier versions.

For IntelliJ IDEA 2021.2.1 and newer versions, these shortcuts have changed to Ctrl+Alt+Shift+(Right/Left/Up/Down) for Windows and Linux and ⌥⇧⌘+Right/Left/Up/Down for macOS.

Note the size of dialog boxes can’t be decreased beyond a certain limit (this applies regardless of whether you are trying to reduce the size using your mouse or keyboard). Also, this shortcut won’t work if you are in an editable component (like text fields or a text area) in a dialog box.

10. Scroll the text in the editor pane without moving the cursor position

Often you want to scroll the editor pane up or down to read code. If you don’t need to edit the code, you might not need to move your cursor from its current location.

Use Ctrl+Up or Ctrl+Down (or ⌘Up/ ⌘Down) in your editor pane to scroll it without changing the cursor position. You can also use a similar keyboard shortcut, Ctrl+Right and Ctrl+Left (or ⌘Left/ ⌘Right), to scroll the directory structure to the left or right in your Project tool window.

Additional tip: To make it easier to read code and move up or down in the editor pane, you can collapse methods, code blocks, or sets of import statements so they take up minimal space in your editor window. To do this, use Ctrl+Numpad – (Window/ Linux) or ⌘Numpad – (macOS). To expand the code block, use Ctrl+Numpad + (Windows/ Linux) or ⌘Numpad + (macOS). This can be extremely helpful while reading or presenting code when you don’t want unrelated code to distract you or use the real estate on your screen.

If you have a lot of methods in your class and you just want to read the code for a few methods, collapse all the methods and expand just the ones that you want to read. You can collapse all methods by using Ctrl+Shift+Numpad – (or ⇧⌘Numpad -). To expand all the code, use Ctrl+Shift+Numpad + (or ⇧⌘Numpad +). You can also selectively expand just a few code blocks for better code readability.

It can also be useful to jump from one method declaration to another by using Alt+Down (⌃Down) or Alt+Up (or ⌃Up).

On closing

Regardless of whether you prefer using the mouse or the keyboard, we wish you happy developing!

Discover more