IntelliJ IDEA Tips & Tricks

Starting a new line of code – How many keystrokes does it usually take you?

Read this post in other languages:

Starting a new line of code is a simple task, not to mention one of the actions you perform most frequently while coding.

The number of keystrokes it takes usually depends on the cursor position. When the cursor is at the beginning of a line, you might move it to the end of the line, either letter by letter or word by word, or you might use the end key to jump to the end of the line. Once the cursor is at the end, you just hit the Enter or Return key.

This method doesn’t take too terribly long, but since starting a new line is such a frequent action, making it even quicker wouldn’t hurt. Imagine how much time you could save by reducing the number of required keystrokes to just one key combination.

There are shortcuts for this in IntelliJ IDEA! Simply hit Shift+Enter to start a new line below the current line or Ctrl+Alt+Enter (⌥⌘Enter on Mac) to start a new line above the current line. 

Use Shift+Enter to start a new line after the current line

Use the key combination Shift+Enter to start a new line below the current line. You don’t need to move your cursor to the end of the current line beforehand – this shortcut works no matter where the cursor is positioned within the current line.

The new line always starts with the correct indentation.

Use Ctrl+Alt+Enter (or ⌥⌘Enter) to start a new line above the current line

When you want to start a new line above the current line, there’s a shortcut that will help you cut down on the number of keystrokes even further.

Use Ctrl+Alt+Enter (or ⌥⌘Enter) to start a new line before your current line. Again, the position of your cursor within the current line doesn’t matter. When the new line is created, the cursor is placed at the proper position and with the correct indentation.

Summary

Creating a new line above or below your current line is something that you do quite often when you develop your applications. Using a single key combination to do so will help you speed up the coding process, and it’s the “smarter” solution to boot!

Happy developing!

image description