I’m brand spanking new to Unity and Monodevelop AND coding in general.
I’m learning some basic C# now and I’m trying to keep all my code well spaced with lots of comment lines so I can make sense of what I’m typing.
However when I add an end curly bracket to something, for example an else statement, it will automatically collapse all the spaces in the if statement and put curly brackets at the end of the if statement line, instead of in the next line (which is a bit cleaner for me to look at).
Is there a way to turn off this auto re formatting? And if so, could you please explain it specifically?
I’ve looked through the prefs and solution options and I’m sure it’s in there, but I don’t know what to switch on or off.
Many thanks!
Maybe One of the check boxes under Tools -> Options -> Text Editor -> Behavior?
Something doesn't sound right with what you're saying. Can you post the code when it's done the weird formatting? It could be that you have an error and it's unable to figure out how to format correctly because of it (Happens a lot actually).
I know this is an older topic, but for anyone who needs it, go to Options → Source Code → Code Formatting → C# Source Code, open that, click the tab for C# Format, then click edit. In the category Indentation, look under “Statements” and uncheck “within blocks”.
Great - I didn't even know all those options existed. Was able to turn off many auto-formatting behaviors that I found annoying.
Hi Ross - I checked under tools but there wasn’t an Option menu. There are text behaviour modifiers in the Prefs and Solution options but I’m kinda looking for a specific one to help stop this.
I should mention I’m using the latest version of Unity (4.3) and whatever Monodevelop comes with that, and running it on a Mac.
Hi ThePunisher.
Here are some screenshots to help illustrate:
It’s not changing the code or creating errors or anything, but it is annoying especially as I’m learning and want to see everything laid out clearly. The main thing is the curly brackets moving to the end and beginning of lines, that makes it very confusing for me.
That's weird. Maybe the macs mono-develop's menus are different. The option I was thinking might be causing the problem is called "Enable on the fly code formatting" Under Automatic Behaviors. But its grayed out on my system for whatever reason so i can't really test it.
AmiN’s solution worked for me: go to “Tools > Options > Source Code > Code Formatting > C# Source Code > C# Format > Edit (button)”. Then select braces and change everything you want to “End of the line”.
Maybe One of the check boxes under Tools -> Options -> Text Editor -> Behavior?
– Ross_BSomething doesn't sound right with what you're saying. Can you post the code when it's done the weird formatting? It could be that you have an error and it's unable to figure out how to format correctly because of it (Happens a lot actually).
– ThePunisher