# Scalafmt formatter

> **TL;DR**
> Required plugin: Scala: [how to install](get-started-with-scala.html#scala_plugin)

Instead of the default IntelliJ IDEA formatter, you can enable the [Scalafmt](https://scalameta.org/scalafmt/) formatter in your project.

## Configure Scalafmt

Procedure: Enable the formatter

1. In the Settings dialog (`Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS))), go to `Editor | Code Style | Scala`.

2. From the Formatter drop-down list, select Scalafmt.

The list of tabs under the formatter field updates accordingly.

![Scalafmt settings](https://resources.jetbrains.com/help/img/idea/2026.2/scalafmt_settings.png)

Scalafmt has the following formatting options:

* Use IntelliJ formatter for code range formatting: this option is selected by default. When you reformat a code selection in the editor, it will be reformatted with the default IntelliJ IDEA formatter. The code selection formatting is also applied to code snippets generated with various actions and [live templates](using-live-templates.html). The Scalafmt formatter can only reformat the entire file.

* Reformat on file save: if you select this option, IntelliJ IDEA reformats a file when you save it `Ctrl+S` (Windows), `⌘ S` (macOS), `⌘ S` (IntelliJ IDEA Classic (macOS)), `⌘ S` (macOS System Shortcuts), `Ctrl+S` (XWin), `Ctrl+S` (GNOME), `Ctrl+S` (KDE), `Ctrl+X, Ctrl+S` (Emacs), `Ctrl+S` (Sublime Text), `⌘ S` (Sublime Text (macOS)), `Ctrl+S` (NetBeans), `Ctrl+Shift+S` (Visual Studio), `⌘ ⇧ S` (Visual Studio (macOS)), `Ctrl+S` (Eclipse), `⌘ S` (Eclipse (macOS)), switch between the active editor and tool windows, or [execute a run/debug configuration](run-debug-and-test-scala.html).

* Configuration: if IntelliJ IDEA does not find the `.scalafmt.conf` file with the specified formatter version in your project, it uses the current [default Scalafmt version](https://github.com/scalameta/scalafmt/blob/v1.5.1/scalafmt-core/shared/src/main/scala/org/scalafmt/config/Settings.scala#L19). You can [override the default version](#change_scalafmt).

> **Note:**
> IntelliJ IDEA saves this configuration for the current project. If you want to use these settings as the default ones for new projects, go to `File | New Projects Setup | Preferences for New Projects` and save your configuration for Scalafmt.

Procedure: Override the Scalafmt version

1. Create the `.scalafmt.conf` file in the root of your project. Right-click your project and select `New | File`.

![Scalafmt configuration file](https://resources.jetbrains.com/help/img/idea/2026.2/new_scalafmt_config.png)

2. Open the configuration file in the editor and specify the Scalafmt version you want to use along with other formatting options.

3. Access the [Scala formatter settings](#scalafmt_config). IntelliJ IDEA reflects your changes for Scalafmt under the Configuration option.

![Scalafmt settings with changed version](https://resources.jetbrains.com/help/img/idea/2026.2/scalafmt_settings_changed_version.png)

> **Note:**
> When you use Scalafmt for formatting, all IntelliJ IDEA general formatter options are ignored and code formatting is delegated to Scalafmt.

## Reformat code with Scalafmt

Note that the Scalafmt formatter can be applied to the entire file only. If you need to reformat smaller code fragments, they will be [reformatted by IntelliJ IDEA](#idea_formatter).

Procedure:

1. Open the file you want to reformat in the editor.

2. In the main menu, go to `Code | Reformat File` (`Ctrl+Alt+Shift+L` (Windows), `⌘ ⌥ ⇧ L` (macOS), `⌘ ⌥ ⇧ L` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ ⇧ L` (macOS System Shortcuts), `Ctrl+Alt+Shift+L` (XWin), `Ctrl+Alt+Shift+L` (GNOME), `Ctrl+Alt+Shift+L` (KDE), `Ctrl+Alt+Shift+L` (Emacs), `Ctrl+Alt+Shift+L` (Sublime Text), `⌘ ⌥ ⇧ L` (Sublime Text (macOS)), `Ctrl+Alt+Shift+L` (NetBeans), `Ctrl+Alt+Shift+L` (Visual Studio), `⌘ ⌥ ⇧ L` (Visual Studio (macOS)), `Ctrl+Alt+Shift+L` (Eclipse), `⌘ ⌥ ⇧ L` (Eclipse (macOS))) and adjust the settings in the Reformat File dialog.

3. Click Run.

![Reformat file dialog](https://resources.jetbrains.com/help/img/idea/2026.2/Reformat_file_dialog.png)

Learn more from [Reformat code](reformat-and-rearrange-code.html).

