Selecting Edit > Auto Format or pressing CTRL + T on Windows/Linux or CMD + T on MacOS when writing a sketch in the Arduino IDE 2 will automatically format the sketch. It is possible to change the behaviour of this command. In this tutorial we will go through how you can change the behaviour of this command.
You can easily download the editor from the Arduino Software page.
You can also follow the downloading and installing the Arduino IDE 2 tutorial for more detailed guide on how to install the editor.
It is possible to define your own custom configuration of the auto formatter feature in two different ways. The custom configuration of the auto formatter can be set on a global level to cover all sketches opened in the editor, or you can set the configuration to be specific to a sketch.
The formatter tool used by Arduino IDE 2 is ClangFormat. The documentation for the configuration options is here.
If you add a
configuration file to either of the following locations, the Arduino IDE 2 will always use it instead of the Arduino default configuration.
If you are using Windows place the file in:
If you are using Linux place the file in:
If you are using macOS place the file in:
If you add a
configuration file to the root of a sketch, the Arduino IDE will use that configuration when formatting that sketch. This file has precedence over a global formatter configuration file.
Here you can find the default formatting file used in the Arduino IDE 2. If you wish to customize how your auto formatting acts in the IDE then starting with this file is a good idea.
Please note that the custom configuration file completely overrides the Arduino default configuration, rather than merging with it. Any configuration option you don't set in your custom file will be set to the ClangFormat default value.
In this tutorial we went through how to customize the behavior of the
CTRL + T
auto formatter command in the Arduino IDE 2. This tutorial also shows the different scopes that are available for the auto formatter configuration.
CMD + T
You can find more tutorials in the Arduino IDE 2 documentation page.