How to configure Intellij for Tabs to Spaces for Only Certain File types

IntelliJ normally allows you to set indentation settings per language in Code style section of the settings. As far as I know Markdown is not included out of the box and support for it must be installed via plugin. But the plugin doesn't seem to enable Code style configuration for Markdown.

So the only solution I can think of is to set tabs as default indentation in General section of Code style settings and then override it to spaces for individual languages (but that may not be necessary because the code style settings for individual languages will have spaces as default).

One downside of this is that if you work with some filetype other than Markdown which is not natively supported in IntelliJ, it will use tabs even though you might want to use spaces for that filetype.

Alternatively you could create feature request for this functionality either in IntelliJ or the Markdown plugin itself.


EditorConfig can do what you want. Just add a file .editorconfig to the root directory of your IntellJ project. The following .editorconfig example will set all files by default to use the 4-character-wide tab character as the indentation, and then a list of other files (and everything in the directory dir2) to use 2 spaces as the indentation.

#top-most EditorConfig file
root = true

[*]
indent_style = tab
indent_size = 4

[{File1.ext,dir1/file2.ext,dir2/*}]
indent_style = space
indent_size = 2

The file matching format is pretty versatile.

IntelliJ IDEA (and some other JetBrain products) should have this installed by default with no need for a plugin. Others may need a plugin.

I would personally recommend adding these other configs for general compatibility and cleanliness

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true