简体   繁体   English

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

[英]how to apply .editorconfig to existing project in intellij

I have created a .editorconfig file as shown below for intellij我为.editorconfig创建了一个.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

How do i apply this code style to all the files in one shot right know i will open a file and press Ctrl + Alt + l which will do the job is there a way to apply this as the config for all the application in intellij14我如何将这种代码样式应用于一次拍摄中的所有文件,知道我将打开一个文件并按Ctrl + Alt + l这将完成这项工作有没有办法将其应用为 intellij14 中所有应用程序的配置

just enable it... ;)只需启用它...;)

(unfortunately the setting is off by default) (遗憾的是该设置默认关闭)

Settings > Editor > Code Style设置 > 编辑器 > 代码样式

checkbox Enable EditorConfig support复选框启用 EditorConfig 支持

在此处输入图片说明

Make sure to follow the steps in Michal's answer first.确保首先按照Michal 的回答中的步骤进行操作。 If you want to retroactively apply this editorconfig to your existing files, do the following:如果您想将此 editorconfig 追溯应用到现有文件,请执行以下操作:

  • I recommend committing all your files to git so you you can reset to that commit if things did not go as planned.我建议将所有文件提交到 git,这样如果事情没有按计划进行,您可以重置为该提交。
  • Make sure you have a .editorconfig you are happy with.确保您有一个.editorconfig
  • In the 1:Project sidepane, right click on the folder you want to apply the .editorconfig to (eg the root folder of your project)1:Project侧窗格中,右键单击要应用.editorconfig的文件夹(例如项目的根文件夹)
  • Choose Reformat Code , which has the default shortcut ctrl alt L .选择Reformat Code ,它有默认的快捷键ctrl alt L
  • Select "Include subdirectories".选择“包括子目录”。 None of the other options are required.不需要任何其他选项。 Then click "Run".然后点击“运行”。

Your files now follow your .editorconfig file configuration.您的文件现在遵循您的.editorconfig文件配置。

单击文件夹时右键单击下拉列表,并选择重新格式化代码 仅选中“包含子目录”的重新格式化代码对话框

If you added the file after project initialization.如果您在项目初始化后添加了该文件。

You need to add the file .editorconfig on the root of the project.您需要在项目的根目录中添加文件 .editorconfig。

Once happy with you file configuration right click and select synchronize '.editorconfig'对文件配置满意后,右键单击并选择同步“.editorconfig”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM