Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Most file types I want to have tabs converted to spaces. However not in Markdown. I went to the Markdown specific File type and see only limited ability to customize it. Is there some way to define filetype-specific editing behavior in Intellij?

enter image description here

like image 510
WestCoastProjects Avatar asked Oct 27 '14 17:10

WestCoastProjects


People also ask

How do I set tab spacing in IntelliJ?

To toggle between tabs and spaces: On the main menu, choose Edit → Convert Indents, and then choose To Spaces or To Tabs respectively.

How do I change tabs in IntelliJ?

Switch between tabsIn the editor, press Ctrl+Tab . Keep pressing Ctrl for the Switcher window to stay open. Use Tab to switch between tabs and other files.

How do I view tabs and spaces in IntelliJ?

You can use Find Action with ⌘⇧A (macOS), or Ctrl+Shift+A (Windows/Linux), and then type in 'Show virtual space at the bottom of the file'.

How do I set default indentation in IntelliJ?

If you need to adjust indentation settings, in the Settings/Preferences dialog ( Ctrl+Alt+S ), go to Editor | Code Style. On the appropriate language page, on the Tabs and Indents tab, specify the appropriate indents options and click OK.


3 Answers

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.

like image 135
Bohuslav Burghardt Avatar answered Oct 18 '22 22:10

Bohuslav Burghardt


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
like image 2
Dakusan Avatar answered Oct 18 '22 21:10

Dakusan


I used it as a workaround, Editor->Code Style->Other File Types

like image 1
FantomX1 Avatar answered Oct 18 '22 20:10

FantomX1