15

When I use code formatting with MonoDevelop (Shortcut: Ctrl+I), everything gets double-indented:

namespace Example
{ 
        public class Test
        {
                public static void Main(string[] args)
                {
                        for (int i = 0; i < 10; i++)
                        {
                                Console.WriteLine("{0}: Test", i);
                        }

                    //this would be the desired indentation width!
                        //Not this!
                }
        }
}

Checking with the preferences under Source Code -> Code Formatting -> C# source code under Text Style, Tab width and Indent width are set to 4. Nevertheless, I get an indent width of 8 instead of 4, so twice as much indentation.

I'm working on a team-project with Unity3D and using MonoDevelop-Unity version 4.0.1.

Mobiletainment
  • 22,201
  • 9
  • 82
  • 98
  • 1
    Ran into this using Unity and MonoDevelop on my Mac. Glad this question was asked! –  Jul 16 '14 at 06:02

1 Answers1

23

It turned out that the solution/project itself had a different code formatting applied and it was overriding my settings from the preferences.

To adjust the solution/project specific settings, right click on the Solution/Project and choose Options. Under Source Code->Code Formatting->C# source are the actual tab width and indent width settings for this solution/project that are applied upon code formatting.

Mobiletainment
  • 22,201
  • 9
  • 82
  • 98
  • For me it seems that opening Solution Options and toggling a checkbox changed the behavior unexpectedly. I'm guessing a bug in options handling. – AndrewS Feb 14 '14 at 06:01