Today I’ll show you a little trick to get better productivity with IntelliJ IDEA, one of the most popular IDEs for Java development, thanks to keyboard shortcuts. Describing all of IntelliJ IDEA’s countless features is of course beyond the scope of a simple blog post. Many of those features are quickly accessible via keyboard shortcuts. We’ll see how to create a custom keyboard shortcut when none is available for a given action.
In the following tutorial we’ll create keyboard shortcuts for two actions from the code editor: Decrease Font Size and Increase Font Size.
Accessing the Search Everywhere window
Although there’s no built-in keyboard shortcut for the Decrease Font Size action we can easily access it via Search Everywhere window:
- hit
SHIFT
twice to bring up the Search Everywhere window - start typing decrease font size in the search box (the search will be case insensitive)
- when the Decrease Font Size action shows up in the dropdown menu select it with the
ARROWDOWN
key - hit
ENTER
- repeat as many times as necessary
The same applies for the Increase Font Size action.
The following animated .gif shows both procedures: first the font size gets decreased 3 times, then it gets increased back 3 times.
As you can see the procedure above is pretty cumbersome. This is why we are going to create keyboard shortcuts.
Creating keyboard shortcuts
We want to create keyboard shortcuts to decrease/increase font size quickly. We want to be able to decrease the font size with ALT+SHIFT+NUMPAD MINUS
and increase the font size with ALT+SHIFT+NUMPAD PLUS
. I’ve chosen these two combinations because they are not taken in IntelliJ’s default configuration yet. As a consequence, if you have never created custom keyboard shortcuts before, you should not incur in any sort of conflict. There are two ways to create keyboard shortcuts. We’ll start with the more standard way.
From the Settings menu
To create our keyboard shortcuts from the Settings menu:
- open the Settings menu (either File > Settings or
CTRL+ALT+S
) - select the Keymap submenu from the left
- filter the actions list by typing font size in the search box on the right
- right click Decrease Font Size from the list then click Add Keyboard Shortcut, a popup will open
- hit the desired combination of keys (
ALT+SHIFT+NUMPAD MINUS
) - click the OK button in the popup
- right click Increase Font Size from the list then click Add Keyboard Shortcut, a popup will open
- hit the desired combination of keys (
ALT+SHIFT+NUMPAD PLUS
) - click the OK button in the popup
- click the OK button on the bottom right corner of the Settings menu window
Don’t be afraid of overriding existing keyboard shortcuts: if you pick a combination that is already taken you’ll get a warning. Look what happens when I try to assign the shortcut ALT+SHIFT+I
(associated by default to the Inspect Code action) to the Increase Font Size action.
From the Find Action window
There’s a fast route to create our keyboard shortcuts as well. You may want to give it a try, because it can be a significant time saver. Here’s the list of steps to follow:
- hit
CTRL+SHIFT+A
to bring up the Find Action window - start typing decrease font size
- when the Decrease Font Size action shows up in the dropdown menu select it with the
ARROWDOWN
key - hit
ALT+ENTER
, the shortcut creation popup will open - hit the desired combination of keys (
ALT+SHIFT+NUMPAD MINUS
) - click the OK button in the popup
- repeat to assign the Increase Font Size action the
ALT+SHIFT+NUMPAD PLUS
shortcut
Notice that when you retrieve any command from the Search Everywhere or Find Action window the keyboard shortcut (if any exists) will appear next to the action’s name. You can take advantage of this feature to discover the keyboard shortcuts of your favourite IDE commands.
The next time you select any of the IDE’s actions from the Find Action menu and you see there’s no associated keyboard shortcut you might consider creating one straight away by hitting ALT+ENTER
.
Using keyboard shortcuts
Needless to say, now that we created keyboard shortcuts we can decrease/increase font size in our IDE at a much faster pace, as you can see below.
Conclusion
We saw how, thanks to custom keyboard shortcuts, we can reach a higher productivity with IntelliJ IDEA. The IDE is rich with commands and the most important ones have their own keyboard shortcuts. Nevertheless, there’s the chance that you frequently end up using some command that has no predefined shortcut. If that’s the case, creating your own custom shortcut can be a great way to boost your programming speed and make your developer’s life a bit easier.