How to autoformat code on array initialization?
Asked Answered
Z

3

11

Every time I have array initialization and try to format the code by pressing CTRL+K and CTRL+D, the code indent doesn't get formatted automatically.

Sample code.

var users = new[]
{
    new User(),
    new User (     ),
       new User { Id = 1 },
    new User {     Id = 1 }   ,
            new     User { Id = 1 }   ,
    new    User { Id = 1      },
};

Expected result.

var users = new[]
{
    new User(),
    new User(),
    new User { Id = 1 },
    new User { Id = 1 },
    new User { Id = 1 },
    new User { Id = 1 },
};

My indenting setting.

Setting

Already tried installing Code Maid and pressing shortcut in the following menu (Format Document, Format Selection).

Menu

Zitazitah answered 6/8, 2014 at 16:48 Comment(8)
try ctrl +e, d. On some copies of visual studio, that is somehow the default instead.Preindicate
@pquest, still doesn't work, is there any patch that I can download to fix it?Zitazitah
not that I am aware of. This is kind of lame, but removing and the replacing the semicolon at the end will probably fix it.Preindicate
@pquest, still not workingZitazitah
If you go to Edit|Advanced|Format Document, what's the keyboard shortcut it lists?Crass
@Hammerstein, I edited the question, and already tried both of them tooZitazitah
Do you have some invalid syntax somewhere else? It's the only other thing I can think of that stops formatting.Crass
No, it compiled successfully, does it work on your visual studio ?Zitazitah
G
0

Select your block of code and use CTRL+E , \ which deletes horizontal white space. Then tabify the code as desired.

You can also find this under EDIT --> ADVANCED --> Delete horizontal white space from your Visual Studio menu.

Gabor answered 6/8, 2014 at 17:34 Comment(2)
hmmmm I needed to press the shortcut one by one on each white spaceZitazitah
@YuliamChandra it works for me when I select the whole block.Gabor
S
-1

Check out this CodeMaid -Extension for Visual studio.

Shondrashone answered 6/8, 2014 at 17:4 Comment(1)
already installed and pressed CTRL+M and Space, but it's still not workingZitazitah
B
-1

Highlight that section of the text and try to press CTRL+K+F or CTRL+K, CTRL+F

Bewail answered 6/8, 2014 at 17:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.