Automatic code formatting is a powerful feature in IntelliJ IDEA that helps maintain code consistency but can sometimes interfere with developers’ preferred style or workflow. If you find that IntelliJ IDEA’s automatic formatting is disrupting your coding process or you want more control over when and how your code is formatted, this guide is for you. Here, we’ll explore practical, step-by-step methods to disable or customize automatic code formatting in IntelliJ IDEA, ensuring you can work in the way that best suits your development style.
1. Disable ‘Reformat on Save’ in Settings
One common cause of automatic formatting is the ‘Reformat on Save’ feature. To turn this off, go to File > Settings > Tools > Actions on Save (or Preferences > Tools > Actions on Save on macOS). Uncheck the box labeled Reformat code. This prevents IntelliJ from automatically reformatting your code whenever you save, giving you full control over when formatting occurs.
2. Turn Off ‘Reformat Code’ on Commit
By default, IntelliJ IDEA may reformat code during commits if the setting is enabled. To disable this, navigate to VCS > Commit. In the commit dialog, look for the checkbox labeled Reformat code and uncheck it. Disabling this ensures that your code remains unaltered during commits unless you manually trigger formatting, which is especially useful in team environments where consistency is managed differently.
3. Disable ‘Code Style’ Auto-Formatting via ‘Editor’ Settings
IntelliJ IDEA applies code style rules automatically based on your configured settings. To prevent auto-formatting, go to File > Settings > Editor > Code Style. Here, you can modify or disable specific code style rules, but to stop automatic formatting entirely, consider setting the ‘Enable formatting’ options to manual or adjusting the ‘Formatter’ settings under Other Settings > Formatter. This way, formatting only occurs when you explicitly invoke it.
4. Remove or Adjust ‘File Watchers’ That Auto-Format
Some projects use ‘File Watchers’ to automate tasks like code formatting upon save or file change. To disable these, go to File > Settings > Tools > File Watchers. Find any watchers related to code formatting tools like Prettier, ESLint, or similar, and disable or delete them. This prevents external tools from reformatting your code without your direct command.
5. Disable ‘Auto-Indent’ and ‘Smart Keys’ Formatting Features
IntelliJ IDEA includes features like auto-indentation and smart key handling that can cause automatic formatting during typing. To disable these, navigate to File > Settings > Editor > General > Smart Keys. Uncheck options like Auto-indent and Smart indent on Enter. This stops the IDE from reformatting or adjusting indentation automatically as you type, giving you more precise control.
6. Use ‘Disable Live Templates’ or Customize Them
Live templates can trigger automatic code snippets and formatting. To manage these, go to File > Settings > Editor > Live Templates. You can disable specific templates or create custom ones that do not auto-format. This helps prevent unexpected code changes when inserting templates.
7. Switch to Manual Formatting with Shortcut
Instead of relying on automatic formatting, you can set your workflow to manual. Use Code > Reformat Code or the shortcut Ctrl + Alt + L (Windows/Linux) or Option + Command + L (macOS). This way, formatting only occurs when you explicitly trigger it, giving you full control over when your code is formatted.
8. Disable or Reconfigure ‘Code Cleanup’ Settings
Code cleanup operations can automatically reformat code based on predefined profiles. To disable or adjust this, go to Code > Optimize Imports > Reformat Code. You can uncheck ‘Reformat code’ or modify the cleanup profile to exclude formatting steps. This prevents automatic reformatting during code cleanup operations.
9. Use a Custom Code Style Profile
If you want to maintain some formatting but prevent automatic changes, create a custom code style profile. Navigate to File > Settings > Editor > Code Style and click the gear icon to create a new profile. Customize the rules to your preference, and avoid enabling any features that trigger auto-formatting, then select this profile explicitly when needed.
10. Disable ‘Format on Paste’
IntelliJ IDEA can automatically reformat code snippets when pasting. To disable this, go to File > Settings > Editor > General > Smart Keys. Uncheck Reformat on paste. This allows you to paste code without automatic reformatting, maintaining your original layout until you choose to reformat manually.
How to Choose
When deciding which method to disable automatic code formatting, consider your workflow and team standards. For instance, if you prefer to format code manually to maintain consistency, disabling ‘Reformat on Save’ and ‘Reformat on Paste’ makes sense. If your team relies on shared formatting profiles, adjusting or disabling ‘Code Style’ auto-application ensures everyone maintains their preferred style. The key is balancing control with convenience—select the options that align with your development process and avoid unintended code changes.
Frequently Asked Questions
- Can I disable all automatic formatting features in IntelliJ IDEA? Yes, by turning off ‘Reformat on Save’, ‘Reformat on Paste’, and adjusting code style settings, you can prevent most automatic formatting.
- Will disabling auto-formatting affect version control diffs? Not directly. However, inconsistent formatting might make diffs harder to read, so consider team standards when disabling features.
- How do I re-enable formatting if I change my mind? Simply re-enable the respective settings, such as ‘Reformat on Save’ or ‘Reformat on Paste’, or trigger manual formatting with Ctrl + Alt + L.
- Does disabling auto-formatting improve performance? In large projects, reducing automatic formatting can improve IDE responsiveness, especially during rapid editing.
- Can I customize formatting rules without enabling auto-format? Yes, you can set up custom code style profiles and manually apply formatting when needed, giving you flexibility without automatic changes.
Final Thoughts
Controlling automatic code formatting in IntelliJ IDEA is straightforward once you understand the available settings. Whether you want to disable it entirely or just tweak specific behaviors, the IDE provides granular options to suit your workflow. The key is to experiment with these settings to find a setup that minimizes disruptions while maintaining code quality. Remember, manual formatting remains a powerful way to ensure your code looks exactly how you want, exactly when you want it.