【问题标题】:how to apply .editorconfig to existing project in intellij如何将 .editorconfig 应用于 intellij 中的现有项目
【发布时间】:2017-01-07 06:46:08
【问题描述】:

我为 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 +Alt +l 这将为该文件完成这项工作,但是有没有办法将此作为 intellij14 中所有应用程序的配置应用?

【问题讨论】:

    标签: intellij-idea configuration formatting editorconfig


    【解决方案1】:

    只需启用它... ;)

    (可惜这个设置默认是关闭的)

    设置 > 编辑器 > 代码样式

    复选框启用 EditorConfig 支持

    【讨论】:

      【解决方案2】:

      请务必先按照Michal's answer 中的步骤操作。如果您想将此 editorconfig 追溯应用到现有文件,请执行以下操作:

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

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

      【讨论】:

      • 这就是我要找的答案,谢谢!
      【解决方案3】:

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

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

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

      【讨论】:

      • 您所指的“同步 .editorconfig”选项在哪里?
      猜你喜欢
      • 2016-11-14
      • 2012-10-04
      • 1970-01-01
      • 2012-12-12
      • 1970-01-01
      • 2022-01-03
      • 2018-07-12
      • 2016-01-14
      • 1970-01-01
      相关资源
      最近更新 更多