Reformat Your Code

Reformat a specific piece of code or the whole file according to your preferences.

The Problem

You're busy hammering out line after line of amazing code but when you're done, and you look up to marvel at your masterpiece, you see that the indentation is all wrong.

The Solution

You can quickly reformat the whole file by invoking "Reformat Code" ⌘⌥L (macOS) / Ctrl+Alt+L (Windows/Linux).

reformat-file-java.png

As you'd expect, this works in any JetBrains IDE.

reformat-file-python.png

However, what if you just want to reformat just one block of code? For example, maybe the whole team changed their code style, and you don't want a large full file reformat to be part of this specific commit. In that case, select the code you want to reformat and again invoke "Reformat Code" ⌘⌥L (macOS) / Ctrl+Alt+L (Windows/Linux).

reformat-block-c-sharp.png

You can reformat code at the directory level too! Invoke your Project tool window ⌘1 (macOS) / Alt+1 (Windows/Linux), select the directory you want to reformat and invoke "Reformat Code" ⌘⌥L (macOS) / Ctrl+Alt+L (Windows/Linux) again. A word of warning here, you probably don't want to mix large commits that include reformatting and code changes - it can make deciphering the commit harder for the next person.

Lastly, there are additional settings you can use for reformatting your code which you can access by invoking the "Reformat Code Dialog" ⌘⌥⇧L (macOS) / Ctrl+Alt+Shift+L (Windows/Linux). The options here will vary depending on which type of code you're working with so try it out and see what you can learn!

reformat-options.png

Want to learn more?

call to action image

Check out the in depth reformatting tutorial for IntelliJ IDEA

Learn More


Related Resources

Bind Arguments to Godot's Callables
Bind Arguments to Godot's Callables
When reusing functionality for signals, use Callable and bind arguments
Navigation Bar - All the power!
Navigation Bar - All the power!
The Navigation Bar can do much more than you think!