How to setup Code Formatting in my IDE?

Tharika Madurapperuma
3 min readNov 22, 2020

Code formatting is something that is really important for making code easily navigable and readable. I will explain how you can add a code formatter to your IDE so that you can make sure your code always meet those criteria.

I will specifically be focussing on setting up a code formatter in IntelliJ Idea IDE which is one of the mostly used IDEs we have now. For demonstration purpose I will be adding the code formatter that is used in WSO2 code for code formatting.

You can access the code formatter used here, from this link to my GitHub gist. WSO2_Eclipse_Code_Formatter.xml

Step 1 :

Go to “Preferences” in IntelliJ Idea Window as shown in the image below.

Select Preferences in IntelliJ Idea

Step 2 :

Then go to “Editor” → “Code Style” → “Scheme” → “Import Scheme” → “Eclipse XML Profile”

Note that the type of the profile depends on the external scheme that you try to import. In our case this is an eclipse xml profile. Therefore we have to select the second option in the drop down menu.

Import the code formatter

Step 3 :

Select the formatter and then click on “Apply” → “OK”.

Step 4 :

In order to apply the formatting to a piece of code in the IDE, you need to select the code block and press the following keys together.

In Windows / Linux,

Shift + Alt + Ctrl + L

In Mac

Shift + Option + Command + L

Then click “Run”.

Select the code and run the formatter

You have now successfully setup a code formatter in your IDE and formatted a code block to be in line with the formatting rules specified in the formatter.

On an additional note, if you need to override some of the code formatting options given by the scheme, access the “Code Style” window from preferences and select the specific programming language. Then do the changes you need, click on “Apply” → “OK”.

Override styles

Thank you for reading the article!

If you find any outdated content or issues with this article, please feel free to create an issue at Developer Corner Git repository here. Let’s grow together and help others in their journey too!

If you like this article please give it a clap. 🙂

Cheers!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response