Managing Code Style on a Directory Level with EditorConfig
As we announced a short while ago, in the upcoming version 2019.2, IntelliJ IDEA and other IntelliJ-based IDEs are extending EditorConfig support, thus allowing you to manage all code style settings for each set of files individually. All you need to do is place an .editorconfig
file in the root directory containing the files whose code style you want to define. You can have as many .editorconfig
files within a project as needed, so you can specify different code styles for different modules. All options from the .editorconfig
file are applied to the directory where it resides as well as all of its sub-directories on top of the current project code style defined in Settings/Preferences | Editor | Code Style. If anything is not defined in .editorconfig
, it’s taken from the project settings.
In v2019.2, in addition to the standard EditorConfig options, we are adding a bunch of custom IntelliJ IDEA options, so now you can conveniently manage all your code style settings on the directory level.
The options are divided into the following categories:
- Standard options such as
indent_size
,indent_style
, and so on. These options do not have any domain-specific prefixes. - Generic IntelliJ IDEA options that have the
ij_
prefix and are applicable to all languages:ij_visual_guides
ij_formatter_off_tag
ij_formatter_on_tag
ij_formatter_tags_enabled
ij_wrap_on_typing
ij_continuation_indent_size
ij_smart_tabs
- Common IntelliJ IDEA language options supported by many (but not all) languages. They start with the
ij_any
prefix, for example,ij_any_brace_style.
- IntelliJ IDEA language-specific options starting with the
ij_<lang>_
prefix where<lang>
is the language domain ID (normally a lower-case language name). For example,ij_java_blank_lines_after_imports
.
Note: The same options may be defined as a common option and a language-specific option, for example, ij_<...>_brace_style
. Language-specific options have higher priority over common or generic options.
Try it Out
Let’s give this feature a try using the ij_visual_guides
option.
- In the Project view, select a source directory and select New | EditorConfig File from the context menu:
- To create an empty file, do not select any properties in the dialog that opens:
- Add the following line:
ij_visual_guides = 40,60
(once you start typing, code completion will suggest the available properties). You will immediately see visual guides appear at columns 40 and 60:
Preview Code Style Settings
You can now easily preview how changes to your code style settings will impact the actual source files. To do this, click the eye icon in the left gutter of the EditorConfig
file and select a source file affected by it. The preview of this file will open on the right:
You can make changes in the Preview pane to try and test how your configuration changes are reflected without worrying about making unwanted changes to the source code – all these changes are discarded when the EditorConfig
file is closed.
If you’re excited to try this feature right now without having to wait for the release, download a new IntelliJ IDEA 2019.2 EAP build right now from our website or update using the ToolBox App.
Please share your feedback with us here in the comments section, in our issue tracker, or on Twitter.
Happy Developing!
R. G. says:
June 28, 2019Great that there will support for changes in the editor but I think that this example is way limited. I personally don’t see that this post adds anything with content to the blog. 🙂
Is it because you expect us to ask what do we want to see?
Is that a real world use case of editorconfig?
Anna Gasparyan says:
July 1, 2019This example merely illustrates how configuration changes can be previewed. You can play with changing any other properties and checking how these changes affect your source files.
Marc Schumacher says:
June 29, 2019Cool feature, but where do I find the full list of supported properties for IntelliJ?
Best, Schumi
Anna Gasparyan says:
July 1, 2019When you right-click a folder and select New | EditorConfig File, check the IntelliJ IDEA-specific checkbox in the dialog that opens and, if needed, select the languages used in your project. An
.editorconfig
file will be generated with all IntelliJ-specific properties listed as commentsphil swenson says:
July 1, 2019I would love to see a .project-config, .run-config files in addition to this…. the xml .idea files are inscrutable and very hard to automate/share. and throw in a .keybindings file too while you’re at it 😉
currently setting up idea projects is painful and manual… no one shares the configs, it’s re-create manually for everyone. I know some check in the .idea folder but few do.
jetbrians could start the equivalent for .editorconfig for other types of functions!
Anna Gasparyan says:
July 8, 2019You’re welcome to file a feature request at https://youtrack.jetbrains.com/
Vojtech Ruzicka says:
July 8, 2019I really like gutter icons which indicate that some section is overriding/being overridden by another section.
For example, some settings in [Java] section are overriding others in [*].
However, it looks like it now works just in the same .editorconfig file. It would be a lot more useful if it could detect overrides across the whole config file hierarchy.
For example, a nested editor config file a few levels deep would show it is overriding some settings from the root editor config file etc.
It would be a cool extension to the current feature. Is this planned for the final release or is it something you would consider implementing? Thanks a lot.
Anna Gasparyan says:
August 6, 2019The behavior you’re describing is actually the way it is meant to work.
If it doesn’t work for you, please report an issue to https://youtrack.jetbrains.com/
Andrei says:
July 30, 2019When will this be available on other intelliJ-based ide’s? For example on Android Studio, App Code and etc.
Anna Gasparyan says:
September 20, 2019If this functionality is not bundled with the IDE you’re using, you can get the EditorConfig plugin: https://plugins.jetbrains.com/plugin/7294-editorconfig
Asaf Mesika says:
August 5, 2019Is there a way to export existing project code formatting as editorconfig file so all developer using the same project share it?
Kennard Vermeiren says:
September 18, 2019I would like to know this too.
Anna Gasparyan says:
September 20, 2019You can right-click a folder (this can be the project’s root folder) and select New | EditorConfig File. Then select the properties that should be applied to your project files.
Anthony Whitaker says:
December 11, 2019Go to Settings > Code Style > Click Gear Icon next to Scheme > Export > EditorConfig File.
That will create an EditorCofig File matching all the settings in your current scheme.
*Tested in IntelliJ Ultimate 2019.3.