Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

align code statement (type,variable,equal sign,etc) for a group of lines in Visual Studio

Does Visual Studio has tab-customization like in the Microsoft Words?
It is also useful for some dirty refactoring (e.g. block-editing).

With this feature, I don't have to space space space / tab tab tab manually anymore to make it pretty like :-

enter image description here

In Microsoft Words, I can assign selected lines to have customized positions of tab :-

enter image description here

It works like this (-> are the tab characters):-

enter image description here

Edit

Code alignment extension recommend by a solution from VTT doesn't work for this code :-

std::vector<int> cat =std::vector<int>() ;
float zombie=5;

I expect it to be formatted like :-

std::vector<int> cat    = std::vector<int>() ;
float            zombie = 5;

But this is the result (at best):-

std::vector<int>     cat =std::vector<int>() ;
float zombie             =5;

Edit2

Here is an example more similar to the real case:-

MyArray<ManagerAAC   >   packAAC =create  (userData);
MyArray<ManagerANC  >   packANC =createANC  ( userData);
MyArray<ManagerAIC  >   packAIC =createAIC  (userData );
MyArray< ManagerNDX<1>>   packNDX1=generate<1>(userData);
MyArray<ManagerNDX<2>>    packNDX2=generate<2>(userData);
MyArray<ManagerNDX<3>>    packNDX3=generate<3>  (userData);
MyArray<ManagerSSK >      packSSK =createSSK     (userData);

I would be nice if it is formatted to be :-

MyArray<ManagerAAC   >    packAAC =create     (userData);
MyArray<ManagerANC   >    packANC =createANC  (userData);
MyArray<ManagerAIC   >    packAIC =createAIC  (userData);
MyArray<ManagerNDX<1>>    packNDX1=generate<1>(userData);
MyArray<ManagerNDX<2>>    packNDX2=generate<2>(userData);
MyArray<ManagerNDX<3>>    packNDX3=generate<3>(userData);
MyArray<ManagerSSK   >    packSSK =createSSK  (userData);

It also enables block-editing e.g. :-

enter image description here

I want to use it in just a few files (<1% of amount of .h/.cpp).

like image 446
javaLover Avatar asked Apr 27 '17 03:04

javaLover


3 Answers

You can install Code alignment extension. It does not work like Word, but it does format your code without much typing.

like image 84
user7860670 Avatar answered Nov 10 '22 05:11

user7860670


Format it like this:

std::vector<int> cat = std::vector<int>();
float zombie = 5;

and do not waste time on something that doesn't matter.

like image 7
Pavel P Avatar answered Nov 10 '22 03:11

Pavel P


Visual studio does have built in automatic formatting ( Edit -> Advanced ) which can be customised in the options menu ( Tools -> Options -> Text Editor -> [language] -> Formatting)

There you can customise how the formatting behaves, although it may not be precise enough to achieve exactly what you want it should be able to get pretty close.

example options screen

like image 2
Jonny Paton Avatar answered Nov 10 '22 05:11

Jonny Paton