How to use IntelliJ formatter in Vscode

Nithin P M
2 min readMay 24

--

An attempt to unify Java code formatting between Vscode and IntelliJ.

From IntelliJ, export the eclipse formatter file (XML) from settings > editor > Code Style > Java.

IntelliJ settings

In Vscode you can download the extension — Language Support for Java™ by Red Hat which can import settings from XML files.

In Vscode > user — settings.json add the following

    "java.format.enabled": true,
"java.format.settings.url": "https://raw.githubusercontent.com/google/styleguide/gh-pages/eclipse-java-google-style.xml",
"[java]": {
"editor.defaultFormatter": "redhat.java"
}

you can replace the URL with the local file path or a GitHub XML raw file link (of the previously exported IntelliJ XML file)

for more information on the Vscode extension, you can refer following links

However, do note that there still might be differences in formatting between both IDEs (I think it’s due to IntelliJ having a separate IntelliJ code style XML along with Eclipse XML which overrides some rules). I prefer to use the eclipse-java-google-style.xml on both IDEs as it seems more consistent while formatting.

--

--