如何将 .editorconfig 应用于 intellij 中的现有项目

how to apply .editorconfig to existing project in intellij

我已经为 intellij 创建了一个 .editorconfig 文件,如下所示

# editorconfig.org

root = true

[*]
charset = utf-8
insert_final_newline = true
trim_trailing_whitespace = true
end_of_line = lf
indent_style = space
indent_size = 4

[*.js]
indent_size = 4

[{package.json}]
indent_style = space
indent_size = 4

如何一次性将这种代码风格应用于所有文件?现在我将打开一个文件并按 Ctrl +A​​lt +l 这将为该文件,但有没有办法将其作为 intellij14 中所有应用程序的配置应用?

只需启用它...;)

(不幸的是默认情况下设置是关闭的)

设置 > 编辑器 > 代码风格

复选框 启用 EditorConfig 支持

如果您在项目初始化后添加文件。

您需要在项目的根目录下添加文件.editorconfig。

对文件配置满意后,右键单击并 select 同步“.editorconfig”

确保首先按照 中的步骤操作。如果您想将此编辑器配置追溯应用到现有文件,请执行以下操作:

  • 我建议将所有文件提交到 git,这样如果事情没有按计划进行,您可以重置到该提交。
  • 确保您有一个 .editorconfig 满意的。
  • 1:Project 侧面板中,右键单击要应用 .editorconfig 的文件夹(例如项目的根文件夹)
  • 选择Reformat Code,有默认快捷键ctrlaltL .
  • Select“包括子目录”。 None 个其他选项是必需的。然后点击“运行”。

您的文件现在遵循您的 .editorconfig 文件配置。