Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable intellij auto change my code format?

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

like image 742
zjffdu Avatar asked May 05 '15 06:05

zjffdu


People also ask

How do I enable auto format in IntelliJ?

Sometimes code formatting can get out of sync, but there's an easy fix in IntelliJ IDEA. You can use ⌘⌥L (macOS), or Ctrl+Alt+L (Windows/Linux) to reformat a selection of code according to your reformat settings. You can also display the Reformat File dialog with ⌥⇧⌘L (macOS), or Ctrl+Alt+Shift+L (Windows/Linux).

What is reformat code in IntelliJ?

Reformat File dialog If you choose Code | Reformat Code from the main menu or press Ctrl+Alt+L , IntelliJ IDEA tries to reformat the source code of the specified scope automatically. For more details on how to reformat, or exclude files from formatting, refer toReformat code. Item.


4 Answers

For those of you who want to disable formatting just for some specific file(s), there is a way since 2018.3 (IDEA-97848).

Go to Settings > Editor > Code Style > Formatter and add your exclusion pattern(s).

like image 69
Leonard Brünings Avatar answered Oct 01 '22 02:10

Leonard Brünings


I tried disabling trim trailing spaces in code formatting but this doesn't work for my file type '.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.

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

like image 32
nikhiledu Avatar answered Oct 01 '22 03:10

nikhiledu


In Preferences > Tools > Actions on save you have a definition

BUT that can be overwritten by the following one, so check in that order:

In Preferences > Editor > Code style > [language] uncheck reformat on file save.

Update: None of those worked for me, so I change my file, commit without save (DON'T save during commit to avoid data loss, you'll be prompted) and then CTRL-Z. Your file is committed and saved but only with your changes.


FWIW, I'm using Scala, on IntelliJ Community 2021.2, with the Scala plugin.

like image 35
Natacha Avatar answered Oct 01 '22 03:10

Natacha


In the latest IntelliJ Idea (2021.3), Auto formatting can be stopped for one or more file type by going to

Preferences -> Tools -> Actions on save -> Enable or Disable Reformatting action for one or more file type

like image 31
Mayank Patel Avatar answered Oct 01 '22 03:10

Mayank Patel