Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to import Eclipse Java Formatter profile in Visual Studio Code

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 !

like image 860
Sumitiscreative Avatar asked Sep 04 '17 05:09

Sumitiscreative


People also ask

How do I add code formatter in Visual Studio code?

The code formatting is available in Visual Studio Code through the following shortcuts: On Windows Shift + Alt + F. On Mac Shift + Option + F. On Linux Ctrl + Shift + I.

How do I add Java package to Visual Studio code?

If you want to download a new JDK, you can click the download link, or trigger the command Java: Install New JDK in Command Palette (Ctrl+Shift+P). It will open a new view guiding you to download JDKs. Note: To enable Java preview features, see How can I use VS Code with new Java versions.

How do I import code formatter XML into eclipse?

Exporting and Importing Code Templates To import a code template: Click Import to open the "Import Templates" browser. Select the relevant XML file containing the template information. Click Open.


1 Answers

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 to at EditorConfig which has native or plugin support for multiple IDEs / editors.

like image 70
haba713 Avatar answered Sep 19 '22 04:09

haba713