Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual studio - auto formatting - column mode or guidelines

I am using auto formatting by default for all documents, but some parts of code are more readable if they are left in column mode (like this one below).

   switch (itUnit)
    {
        case ItUnit.NotApplicable:        return -1;
        case ItUnit.KilometersPerHour:    return 1;  
        case ItUnit.MetricTons:           return 1;
        case ItUnit.Centimeter:           return 0.01f;

I don't want to stop auto formatting files with column mode style function or two. I am searching for some option to help me with this. Maybe something like EditorGuidelines but that auto format does not ignore them (like it ignores the version I linked). Or some option to mark some parts of code to be ignored by formatter. Or maybe some third party formatter that supports guidelines?

Auto-format will make this:

    switch (itUnit)
    {
        case ItUnit.NotApplicable: return -1;
        case ItUnit.KilometersPerHour: return 1;
        case ItUnit.MetricTons: return 1;
        case ItUnit.Centimeter: return 0.01f;
like image 266
watbywbarif Avatar asked Nov 23 '25 23:11

watbywbarif


1 Answers

Often you can use Undo (ctrl-z) to undo the autoformat change, in particular after pasting a column-aligned line of code. Not ideal, but could help.

Also Tools/Options/C#/Code Style/Formating/Spacing, check "Ignore spaces in declaration statements" can help too.

like image 66
Jeff Spindler Avatar answered Nov 27 '25 00:11

Jeff Spindler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!