Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to maintain C++ array formatting when using VScode's default formatter upon saving?

When using the default VScode formatter for c++. I want to keep format on save but I don't want the array to be changed this drastically.

It changes an array from this

    const int level[] =
    {
        0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
        0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0,
        1, 1, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3,
        0, 1, 0, 0, 2, 0, 3, 3, 3, 0, 1, 1, 1, 0, 0, 0,
        0, 1, 1, 0, 3, 3, 3, 0, 0, 0, 1, 1, 1, 2, 0, 0,
        0, 0, 1, 0, 3, 0, 2, 2, 0, 0, 1, 1, 1, 1, 2, 0,
        2, 0, 1, 0, 3, 0, 2, 2, 2, 0, 1, 1, 1, 1, 1, 1,
        0, 0, 1, 0, 3, 2, 2, 2, 0, 0, 0, 0, 1, 1, 1, 1,
    };

to this

    const int level[] = {
        0,
        0,
        0,
        0,
        0,
        0,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        0,
        1,
        1,
        1,
        1,
        1,
        1,
        ...

    };

I want to keep format on save but I don't want the array to be changed this drastically.

like image 234
Aiden Rand Avatar asked Jan 23 '26 13:01

Aiden Rand


1 Answers

Not sure if you are trying to keep using the default formatting engine for some reason, I can't find an option to change this behavior using the default, but this behavior is not present when setting the option C_Cpp:Formatting (Extensions > C/C++ > Formatting > C_Cpp: Formatting) to vcFormat. If you just want format on save to not elongate your arrays Id use that engine option.

like image 92
Douglas B Avatar answered Jan 26 '26 01:01

Douglas B