Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Extension for Code Alignment [closed]

Is there any free extension to perform code alignment, like Align Assignments with Productivity Power Tools but to align this code:

public int ID;
public string Title;
public string Text;
public decimal Factor;

in that way, or something like that?

public int      ID;
public string   Title;
public string   Text;
public decimal  Factor;
like image 759
Alexei Avatar asked Sep 27 '11 07:09

Alexei


People also ask

How do I fix the alignment code in Visual Studio?

How do you fix code alignment in VS code? On Windows: Shift + Alt + F. On Mac: Shift + Option + F. On Linux: Ctrl + Shift + I.

How do I auto align code in Visual Studio?

Auto formatting settings in Visual Studio Show activity on this post. Select the text you want to automatically indent. Click menu Edit → Advanced → *Format Selection, or press Ctrl + K , Ctrl + F . Format Selection applies the smart indenting rules for the language in which you are programming to the selected text.

How do you close extensions in VS Code?

To uninstall an extension, select the Manage gear button at the right of an extension entry and then choose Uninstall from the dropdown menu. This will uninstall the extension and prompt you to reload VS Code.


2 Answers

As Pop Catalin said, Code alignment is what you're after. It's my extension, sorry for not much documentation. It's something that's so much easier to explain with videos, but I'm still to get around to it.

When you align by string it finds the first instance of the string and lines them up. For example if you were to enter '=' then

foo = bar;
foobar = foo;

would become

foo    = bar;
foobar = foo;

However, your code doesn't have a common delimiter - except for the space before it. So you can use Align By Space (from the toolbar or ctrl + =, ctrl + space, but you'll have to remove what's already assigned to ctrl + =). Align By Space uses your caret location (you can still select the row you want to align, or let the extension figure it out) and aligns by the first space on each line after your caret location.

Hope that makes sense!

like image 138
Chris McGrath Avatar answered Nov 05 '22 13:11

Chris McGrath


You can try Code alignment ;)

P.S. I haven't tried it myself but it looks like it does what you need, so if it's good you can leave a comment here, so more people will know.

like image 5
Pop Catalin Avatar answered Nov 05 '22 14:11

Pop Catalin