2

How would I go about configuring a formatter (in my case, the Visual Studio Code C/C++ formatter) to indent with tabs, but align with spaces?

I've looked at this post and this post, but they were asked more than 5 years ago and I'm wondering if anyone has some new information to share.

I don't mind manually typing out the spaces to align, I just don't want the formatter to convert 4 spaces into a tab.

For reference, I would like my code to be formatted like this, where ---> indicates a single tab and . indicates a single space:

if (condition) {
--->aLongFunction(something).// does something
--->a(b).....................// does something else
}

If I save this code, Visual Studio Code will format it as such:

if (condition) {
--->aLongFunction(something).// does something
--->a(b)--->--->--->--->--->.// does something else
}

This is bad because if someone else wants to look at my code and they have their tab-width set to 2, it would look like this:

if (condition) {
->aLongFunction(something).// does something
->a(b)->->->->->.// does something else
}

And now it is no longer aligned, just strangely spaced out!

I think I value alignment more than I value tabs, so if it comes to it, I will simply switch to use spaces over tabs, but it would be nice if the formatter could see what I'm trying to do!

0 Answers0