IDE

IntelliJ IDEA Keyboard Shortcuts Tutorial

The developers, systems administrators, etc., when dealing with files, have the need of being able to perform actions without depending on the mouse. Not only for speed and comfort, but also to avoid injuries related to the mouse usage, like RSI ones (Repetitive Strain Injury).

This tutorial will show the most useful shortcuts for IntelliJ IDEA, the JetBrains IDE for Java, Groovy, and other languages.

For this tutorial, we will use:

  • IntelliJ IDEA 2016.1.2 Community Edition (free and open source).
  • Linux Mint 17.03.

You can download the IDE from the official JetBrains website, available for Linux, Windows and MacOS.

1. Editing

Basic code completion: Ctrl + Space

For completing keywords, variables, methods, etc.

Smart code completion: Ctrl + Shift + Enter

This is how IntelliJ IDEA defines its smart code completion:

Smart Type code completion filters the suggestion list and includes only those types that are applicable to the current context.

That is the reason of considering it “smart”.

Let’s see how it works with an example:

1. Using the smart code completion.

That is, using this shortcut, in a return statement in this case, the IDE knows that value will probably be the value to complete the statement with, even before starting typing the word.

Comment/uncomment line/selection with line comment: Ctrl + /

For example, if we would select the following lines:

public static void main(String[] args) {
    System.out.println("Hello world!");
}

This shortcut would comment each line with //:

//public static void main(String[] args) {
//    System.out.println("Hello world!");
//}

Comment/uncomment line/selection with block comment: Ctrl + Shift + /

Exactly the same as the previous one, but this for block comments surrounded with /* */.

Delete line at cursor: Ctrl + Y

Also works for the selection, but this is usually done with backspace key. Pressing these keys will delete the line where the caret is placed.

Duplicate current line/selection: Ctrl + D

Just for generating duplicates below the line or selection.

Generate methods (constructor, getters & setters, etc.): Alt + Insert

With this combination, IntelliJ IDEA will prompt the following window:

2. Methods available to be generated automatically.

The getters and setters, and also the constructor, are suggested based on the class attributes.

Override parent methods: Ctrl + O

Similar to the previous one since the Object methods also appear (hashCode, equals, etc.), but is also applicable for methods of extended classes.

Surround line/selection: Ctrl + Alt + T

This allows to surround the code automatically with control structures such as if, for, try/catch, etc. and also with synchronized or Runnable blocks.

Indent line/selection: Ctrl + Alt + I

The selection will be indented with the specified configuration in Settings/Editor/Code Style, for the language you are working with, in the “Indent” setting.

Reformat code: Alt + Ctrl + L

If the previous one was for indenting the code, this one is for reformatting the code in all of its aspects, for the whole file, again based on the settings defined in Settings/Editor/Code Style.

For example, with this shortcut, we could convert the following disordered code:

public static
void main( String[] args ){System.out.println(  "Hello world!"  )  ; }

To:

public static void main(String[] args) {
    System.out.println("Hello world!");
}

Depending, of course, on the indentation level, spaces before and after braces, etc.

Rename: Shift + F6

This is applicable to any identifier (class names, methods, attributes, variables, etc.). This is done “safely”, i.e., IntelliJ IDEA won’t break anything in the code.

Find & replace: Ctrl + R

This combination shows the typical tool window with two search boxes, one to find the term to replace, and another for the replacement. IntelliJ IDEA also allows to use regular expressions for the finding.

2. Searching/navigating

In this section we will see how to make searches, and also how to navigate through the files.

Find text in current file: Ctrl + F

The classical shortcut for many programs.

Find next coincide: F3 or Enter

Set the selection of the entered text to find in the following coincidence.

Find previous: Shift + F3

The same as the previous one, but for the previous coincidence.

Go to class: Ctrl + N

With this shortcut you can find a go to any class, receiving suggestions, like in the following image:

3. Navigating between classes.

Go to any file: Ctrl + Shift + N

The same as the previous one, but applicable to any file, not only classes.

Go to declaration: Ctrl + B

In this case, we have to place the cursor in element (object, method, attribute, parameter, etc.), and the IDE will navigate to the place of its declaration, even if it is in another file.

Go to implementations: Ctrl + Alt + B

If we place the cursor in a declaration (interfaces, abstract classes and methods), and we press this combination, IntelliJ IDEA will show a list of the places where it is being implemented to navigate to it, like shown in the following example:

4. Navigating to implementations.

If there’s only one implementation, the IDE will navigate directly to it.

Go to super-method/class: Ctrl + U

This is the same as the previous one, but reverse: navigating to the parent definition of a method or class.

Go to line & column: Ctrl + G

This shortcut will show a window where we can specify the line and column of the current file, to navigate to it. The format is line:column. But if we can also specify only the line, if the column is not necessary.

Switch between tabs: Ctrl + Tab

Just like, e.g., in web browsers.

3. Compiling and running

Compile project: Ctrl + F9

This just makes the project, without running it.

Select configuration and run: Alt + Shift + F10

This allows to configure the project before running it, selecting the main class, setting parameters for the JVM and the program, etc.

Run project: Shift + F10

Runs the project with the configuration set.

Select configuration and debug: Alt + Shift + F9

As same as selecting the configuration and running, but for debugging.

Debug project: Shift + F9

Equal to running the project, but debugging it.

4. Other shortcuts

Find action by name: Ctrl + Shift + A

A very useful shortcut, specially when you are not familiarized with other shortcuts yet. This allows to find any available action or option in IntelliJ IDEA, by the name, like shown in the following image:

5. Finding available actions by name.

Open settings: Ctrl + Alt + S

This will open the settings menu (File/Settings).

Toggle full screen editor: Ctrl + Shift + F12

For entering/exiting the full screen in the editor.

5. Vi/Vim fan? This is for you!

This is not exactly related to the IntelliJ IDEA shortcuts, but it’s worth mentioning.

If you are a former Vim user and you miss its commands, or you still use it and you don’t want to learn other shortcuts, or even if you want to learn to use it but using IntelliJ IDEA, there is a plugin for Vim emulation.

5.1. Installation

  • Open settings menu (Ctrl + Alt + S).
  • Go to plugins menu.
  • Click the “Install JetBrains plugin…” button.
  • Type “IdeaVim” in the search box.
  • Click the “Install” button, and restart the IDE.

5.2. Usage

To use the Vim emulator, the only thing we have to do is to ensure that Tools/Vim Emulator has a tick ✓. If checked, the editor will be in Vim mode. We can activate/deactivate whenever we want.

6. Summary

In this tutorial we have seen the IntelliJ IDEA shortcuts for code edition, navigation between files and compilation and execution of the project. Apart from that, we have also seen the Vim plugin for IntelliJ IDEA, that allows to have a better experience for Vim users.

Julen Pardo

Julen holds his Bachelor's Degree in Computer Engineering from Mondragon Unibertsitatea, in Spain. Currently he is working in Munich, Germany, as Software Engineer. He contributes to open source projects with plugins, and he also develops his own, open-source projects. Julen is continuously trying to learn and adopt Software Engineering principles and practices to build better, more secure, readable and maintainable software.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button