如何禁用intellij自动更改我的代码格式?

时间:2023-01-14 23:30:28

When I edit the java source code, intellij will auto format my code besides the places I edit, how to disable that ?

当我编辑java源代码时,intellij会自动格式化我的代码,除了我编辑的地方,如何禁用它?

2 个解决方案

#1


You can disable IntelliJ IDEA's ability to format (and therefore auto format) specific file types, but it comes at a cost.

您可以禁用IntelliJ IDEA格式化(因此自动格式化)特定文件类型的功能,但这需要付出代价。

To disable :

要禁用:

  1. Settings > Editor > File Types
  2. 设置>编辑器>文件类型

  3. Select the file type you want to have never formatted
  4. 选择您希望从未格式化的文件类型

  5. change the extension to something you don't use - for example '*.styl' to '*.oldstyl'
  6. 将扩展名更改为您不使用的内容 - 例如'* .styl'到'* .oldstyl'

Now, even if you tell IntelliJ to reformat one of these files it won't.

现在,即使你告诉IntelliJ重新格式化其中一个文件,它也不会。

The cost is that you lose syntax highlighting and language support all together. In my case for stylus files it was worth it. IDEA kept removing tab characters in sections of code that I wasn't even working in. SUPER annoying and destructive.

成本是你一起失去语法高亮和语言支持。在我的手写笔文件的情况下,这是值得的。 IDEA一直在删除我甚至没有工作的代码部分中的制表符。超级烦人且具有破坏性。

#2


I tried disabling trim trailing spaces in code formatting but this doesn't work for my file type '.erb'.

我尝试在代码格式中禁用剪裁尾随空格但这不适用于我的文件类型'.erb'。

I added my file type '.erb' to selectively disable code inspection for this file type but this doesn't work in IntelliJ version 2016.2.4.

我添加了我的文件类型'.erb'来有选择地禁用此文件类型的代码检查,但这在IntelliJ版本2016.2.4中不起作用。

I locked my file after I had made the changes using the lock icon in the Status Bar and this finally worked!

我使用状态栏中的锁定图标进行了更改后锁定了我的文件,这终于奏效了!

#1


You can disable IntelliJ IDEA's ability to format (and therefore auto format) specific file types, but it comes at a cost.

您可以禁用IntelliJ IDEA格式化(因此自动格式化)特定文件类型的功能,但这需要付出代价。

To disable :

要禁用:

  1. Settings > Editor > File Types
  2. 设置>编辑器>文件类型

  3. Select the file type you want to have never formatted
  4. 选择您希望从未格式化的文件类型

  5. change the extension to something you don't use - for example '*.styl' to '*.oldstyl'
  6. 将扩展名更改为您不使用的内容 - 例如'* .styl'到'* .oldstyl'

Now, even if you tell IntelliJ to reformat one of these files it won't.

现在,即使你告诉IntelliJ重新格式化其中一个文件,它也不会。

The cost is that you lose syntax highlighting and language support all together. In my case for stylus files it was worth it. IDEA kept removing tab characters in sections of code that I wasn't even working in. SUPER annoying and destructive.

成本是你一起失去语法高亮和语言支持。在我的手写笔文件的情况下,这是值得的。 IDEA一直在删除我甚至没有工作的代码部分中的制表符。超级烦人且具有破坏性。

#2


I tried disabling trim trailing spaces in code formatting but this doesn't work for my file type '.erb'.

我尝试在代码格式中禁用剪裁尾随空格但这不适用于我的文件类型'.erb'。

I added my file type '.erb' to selectively disable code inspection for this file type but this doesn't work in IntelliJ version 2016.2.4.

我添加了我的文件类型'.erb'来有选择地禁用此文件类型的代码检查,但这在IntelliJ版本2016.2.4中不起作用。

I locked my file after I had made the changes using the lock icon in the Status Bar and this finally worked!

我使用状态栏中的锁定图标进行了更改后锁定了我的文件,这终于奏效了!