49

I'm trying to have a standard code style for my project, and I have found http://editorconfig.org/, that is a standard for that. I like it very much, and Intellij supports it (we use Intellij).

But I have read a lot and I haven´t found how I can export all my code styles of Intellij to a .editorconfig file. I only can export them to an XML that is only for Intellij.

Or is there any webpage where I can read ALL the editorconfig domain specific properties for Java? In the editorconfig github wiki they only have a few.

Kedar Mhaswade
  • 4,535
  • 2
  • 25
  • 34
edwise
  • 869
  • 2
  • 9
  • 18
  • Correct me if I'm wrong (I'm actually new to .editorconfig myself), but I don't think there are domain specific properties yet for .editorconfig? You can add pattern matching if you want java files to be configured differently, but the actual number of things you can configure is quite small according to their wiki. What it does show is only ideas for domain specific properties. – Pytry Sep 21 '16 at 21:07

4 Answers4

66

Go to "File->Settings (Preferences in OS X)->Editor->Code Style". At the bottom of the right pane there is a section for Editor Config options, which now includes an "Export" button. This will only export formatting options that are available in the Editor Config specification.

above steps in image format

To include advanced options from IDEA you will have to save IntelliJ specific files with the project.

If you want to do this without saving the entire ".idea" folder and "*.iml" files, you can also export the IDEA configuration to an xml file and save in a place where everyone can get to it.

  1. In "File->Settings->Editor->Code Style". At the top of the right pane, there will be a "Scheme" field with an dropdown of options.
  2. Next to the dropdown is a cog/gear image that will expand to give some options depending on which scheme you have selected.
  3. The two options you need are the "Export..." option and the "Import Scheme" options which do what their names imply.
rogerdpack
  • 62,887
  • 36
  • 269
  • 388
Pytry
  • 6,044
  • 2
  • 37
  • 56
  • 5
    Note this has changed and the setting is under the gear icon to the right of Editor > Code Style > Scheme (I don't have access to be able to amend the screenshot right now) – Brian Agnew Oct 09 '19 at 12:17
  • 1
    See my answer below for a updated screenshot. Pls lift to amend your answer... – Brian Agnew May 20 '20 at 10:39
5

In newer versions @Pytrys solution does not work anymore. Now you have to do it with File -> New -> EditorConfig file: enter image description here

deve
  • 487
  • 1
  • 6
  • 24
  • 1
    That generates a new file, but I'm not sure it exports all your current settings, does it ? – Brian Agnew May 20 '20 at 10:40
  • 1
    @Brian No, unfortunately it exports not all settings. If you want to export all code style settings, have a look [here](https://www.jetbrains.com/help/idea/copying-code-style-settings.html) and [here](https://www.jetbrains.com/help/idea/settings-code-style.html#scheme). If you want to export everything follow [these instructions](https://www.jetbrains.com/help/idea/sharing-your-ide-settings.html#import-export-settings). – deve May 28 '20 at 10:52
  • So this is pretty neat. Now if you export using the `File->New-EditorConfig File` option, it will give you options on which styles you want exported. If you go through `Settings->Editor->Code Style` pane (like I am showing) and then select `EditorConfig File` option, it includes a lot more of the IntelliJ specific style options. I haven't confirmed, but are you saying that to get all of the Code Style settings for Intellij, you still need to export as an intellij code style xml? – Pytry Oct 28 '20 at 15:35
  • Just a follow up. The [documentation](https://www.jetbrains.com/help/idea/configuring-code-style.html#editorconfig) on `.editconfig` seems to imply that all of the IntelliJ styles will get exported, but it isn't clear. – Pytry Oct 28 '20 at 15:46
5

With later Intellijs (I'm using 2020.1), the configuration export is available via Settings -> Editor -> Code Style and then the gear icon. See the screenshot below, and the selected menu options:

enter image description here

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
3

Don't think IntelliJ will do this for you.

You'll probably have to Export IntelliJ's Code Styles as a "Code Style XML File" and then manually parse that to your EditorConfig file. Or find a parser on the internet.

To export all your Code Styles from IntelliJ:

  1. Hit "Ctrl + Alt + S".
  2. Editor > Code Style.
  3. Click the "Manage" button next to where IntelliJ states your Scheme.
  4. Export > Export as Code Style XML File.

HTH

Harmelodic
  • 5,682
  • 1
  • 28
  • 31
  • 1
    Thanks, I already know to do that. I don't know how to parse them :( I think that the editorconfig properties are only a few, and it doesn't have all the posibilities of Intellij code styles :( – edwise Mar 10 '16 at 12:29
  • Most probably. I think the "support" for EditorConfig that IntelliJ provides is simply: If you put .editorconfig files in your project, they will work (as long as you have it enabled). – Harmelodic Mar 10 '16 at 13:45
  • Yeah, it works, but that's the problem... the properties are very simply. – edwise Mar 10 '16 at 14:50
  • Why can't you just edit and use IntelliJ's code styles? What is the advantage of using EditorConfig in your case? – Harmelodic Mar 10 '16 at 14:56
  • 3
    Because editorconfig works only having the .editorconfig file. The developers don't need to import code styles, selecting them, etc, etc. You can add your .editorconfig in your repository (git for example) and.. that's it! Intellij 14 and above supports its, without any configuration. If you want to change some style, you do in the file, push it and it's done. When the other developers do a pull, they have automaticaly the new code styles working. – edwise Mar 10 '16 at 16:51
  • Ah, I didn't realise you wanted code style consistency across a team. Yeah, I think it's just a case of IntelliJ doesn't do it (yet). Throw up a community post for Jetbrains at: https://intellij-support.jetbrains.com/hc/en-us/community/topics **or** find a parser somewhere in the depths of the internet. Let me know if you find anything! – Harmelodic Mar 10 '16 at 17:10
  • Its time to create a plugin for that or make a PR for the existing one, would be great. Like for example export all google code styles to .editorconfig – EliuX Jun 23 '16 at 15:23
  • This reply is DEPRECATED. Now is possible export from IDE. Check others answers. – Nakamoto Sep 24 '20 at 20:15