16

I am looking for solution for importing Eclipse Java Formatter Profile in Visual Studio Code. In order to go with coding complaince. For example in IntelliJ and Eclipse for Java we do this way:

IntelliJ

  1. Download the config (attached)
  2. In the Intellij settings (Ctrl+Alt+S), go to Code Style
  3. Next to Scheme, click Manage and then Import...
  4. Select 'Eclipse XML Profile' and browse to the downloaded config file.

Now, every time Intellij uses its auto-formatting features, it will conform to the standards in the config file. This can be done quickly with the shortcut Ctrl+Alt+L.

Eclipse

  1. Download the config (attached)
  2. Navigate to Window->Preferences
  3. Navigate to Java->Code Style->Formatter
  4. Click on Import and navigate to the downloaded config file
  5. Click Apply and Ok

Now, every time Eclipse uses its auto-formatting features, it will conform to the standards in the config file. This can be done quickly with the shortcut Ctrl+Shift+F.

Note: This profile might not work while formatting xml files. So go to Preferences -> XML -> Editor

I need to know the same alternative for Visual Studio Code. Please share any pointers !

1

1 Answer 1

12

Visual Studio Code

You can use Eclipse Java Formatter Profile in VS Code like this:

  1. Install the extension Language Support for Java(TM) by Red Hat.
  2. File → Preferences → Settings → java.format.settings.url: Set URL (or local file path) pointing to Eclipse Formatter Profile file.

See this wiki page for more information.

P.S. Also take a look at EditorConfig which has native or plugin support for multiple IDEs / editors.

1
  • YMMV but I found that vscode cannot load an eclipse profile if vscode is using WSL as the terminal and the codestyle file is in the Windows filesystem. This I found is true regardless of teh url syntax for local files. I had to copy the file into my WSL filesystem.
    – Robin Coe
    Commented Jan 30, 2021 at 20:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.