When I edit the java source code, intellij will auto format my code besides the places I edit, how to disable that ?
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).
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.
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).
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!
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With