top of page

A few useful IntelliJ keyboard shortcuts

  1. Select blocks of code: from where your cursor is, use Ctrl + W several times to extend the selection around the cursor. Depending on how the code is formatted, the first use of the shortcut will select the word that is found at the cursor position. The second use of the shortcut extends the selection to the expression that contains the initially selected word, than you will select the line of code, then the paragraph, and so on.

  2. Extracting a method from repetitive code: when you realize that your class contains a chunk of code that repeats itself throughout the class, a very easy way to extract the code into a separate method and replace its' occurrences with the new method is to use the Ctrl + Alt + M shortcut. Here, you can choose a name for the new method (if the suggested one is not of your liking), the visibility for the method (by default, IntelliJ suggests to make it private, but you can select another option from the dropdown) and you can declare it static if you want.

  1. Extracting a field: Suppose that throughout your class you are using a parameter of the same value, that can be extracted as a field (for example the integer value 10, like in the screenshot below). This value might change in time, and you would like to hold this value in a field of your class, so that you have easy access to modify it when needed.

  1. Extracting a variable:When you have a property that you use several times in a method, for example a String,by just typing in its' value, it would be very useful to declare it as a method variable. This can be easily done by using the Ctrl + Alt + V shortcut. When doing this, IntelliJ will declare it (having the name the same as the value it holds), initialize it with the value you provided, and prompt you to replace its' occurence within the method (you can choose to either replace each occurence of the String with the new variable, or replace only the occurence you have selected when using the shortcut. You also have a checkbox for making it final, if you wish. An example can be seen below: Before: @Test public void newTest1() { printAString("secondString"); printAString("secondString"); } After @Test public void newTest1() { String secondString = "secondString"; printAString(secondString); printAString(secondString); }

  2. Displaying a method signature: When calling a method that needs to be provided parameters to comply with its' signature, you can use the Ctrl + P shortcut to show you what parameters having what types you must provide for the method, as you type them. If several method signatures exist, they are all displayed, with a highlight on the variant that most closely resembles what you are typing.

  3. Generating getters and setters: Whenever you deal with a large number of properties that need to be declared in a class, manually writing all the corresponding getters and setters is cumbersome and error prone. Therefore, you can use the Alt + Insert shortcut in IntelliJ. From the dropdown menu that appears you can choose to generate the getters or setters, or both, by performing a multiple selection on the values for which you want to generate them (hold Ctrl and click on the values you want).

  4. Generating constructors: When you don't want to write a classes' constructor manually, you can use the Alt + Insert shortcut in IntelliJ, from where you can choose which constructor you want to generate (if you have multiple fields declared in your class, you can generate constructors for a number of these parameters, by performing a multiple selection on the values you are interested in).

  5. Highlight usages in current file: When you want to easily see where a method, field or parameter is used within the current file, you can use the Ctrl + Shift + F7 shortcut after selecting the item you are interested in. All its' occurrences will be displayed on a yellow background.

  6. System.out.println of a variable: If you have a variable whose value you want to print, just type soutv right below the line of code that instantiates it. The output on the console will be 'nameOfVariable = valueOfVariable'

  7. Delete current line: A simple Ctrl + Y will do the trick.

  8. Jump to beginning or end of file: Use Ctrl + Home to jump to the beginning, or Ctrl + End to jump to the end of the file.

  9. Optimize imports: When you don't want to manually remove unused imports or group imports of methods from the same class, you could use the Ctrl + Alt + O shortcut.

  10. Create new line: When your cursor is found on a line of code, after which you want to insert a new line and start typing directly in it, without having to manually move the cursor to the starting position, just use the Shift + Enter shortcut.

  11. Find a file, class, or method in the whole project: Simply use Shift + Shift.

  12. Find a file or class in the whole project: Simply use Ctrl + Shift + N.

  13. Find a method in the whole project: Simply use Ctrl + Alt + Shift + N.

  14. Reformat code: If your code's indentation is not optimal, you can use the Ctrl + Alt + L shortcut either on a selection of code or without any selection (which means it applies to the whole class) to make everything fall into place. For the complete list of IntelliJ's keyboard shortcuts please refer to this link.

Recent Posts

See All
bottom of page