Search code examples
clang-format

How make clang-format indent using tabs instead of spaces?


Testing with the following

clang-format -style="{BasedOnStyle: Google, UseTab: Always}" -i /path/to/file.ino

Results in spaces instead of tabs


Solution

  • Internally, clang-format only works with spaces, its not until the final step it replaces spaces with tabs and then it will only replace them in groups of TabWidth. Since the Google style has IndentWidth: 2 and TabWidth: 4 it wont replace them with tabs unless there are two indents on the same line.

    You'll have to sync up IndentWidth and TabWidth in addition to UseTab for it to work on every line:

    UseTab: Always
    IndentWidth: 4
    TabWidth: 4