Arduino IDE 2 (beta) How to configure indent spaces

I'm trying to configure the IDE Editor, to use 4 spaces instead of 2. I was able to configure version 1 of the IDE changing preferences.txt (editor.tabs.size=4), and formatter.conf (indent=spaces=4). But I cannot find those configuration nor anything similar con Arduino IDE 2 (beta).

Does someone know hot to do this??

Cheers!!!

2 Likes

There are two separate systems to configure:

  • Indentation style while editing
  • Indentation style of the auto formatter

I'll provide instructions you can follow to configure both these things to use your preferred number of spaces:

Editor

The editor behavior can be configured in Arduino IDE's advanced settings:

  1. Press the Ctrl+Shift+P keyboard shortcut (Command+Shift+P for macOS users) to open the "Command Palette".
    A menu will appear on the editor toolbar:
    image
  2. Select the "Preferences: Open Settings (UI)" command from the menu.
    You can scroll down through the list of commands to find it or type the name in the field.
    A "Preferences" tab will open in the Arduino IDE main panel.
  3. Type editor.tabSize in the "Search Settings" field of the "Preferences" tab.
  4. Set the field under the "Editor: Tab Size" setting to your preferred number of spaces.
  5. Close the Preferences tab by clicking its X icon.

Auto Format

The sketch code can be automatically formatted to a standardized style by selecting Tools > Auto Format from the Arduino IDE menus. It is possible to define a custom formatter configuration.

The configuration system is documented in general here:

The standardized formatter configuration file is available from the link in that tutorial. If you would like the formatter to use a different number of spaces, use that file, but change the value of the relevant properties.

For example, if you want an indent of 4 spaces, change this line:

IndentWidth: 2

To this:

IndentWidth: 4

Related discussion:

2 Likes

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.