1

I own Visual Studio 2015 Enterprise and I'm unsure about making VS' Smart Indent feature use my coding style, so far I've configured most of it, except for ternary operators. Example:

bool bSomeBoolean = true;

// my code
for(int i = 1; i <= 39; i++)
{
    Console.WriteLine(bSomeBoolean? "Yes":"No");
}

// smart indent
for(int i = 1; i <= 39; i++)
{
    Console.WriteLine(bSomeBoolean ? "Yes" : "No");
}

VS will add the space before the question mark, also before and after the colon.

How could I stop it from happening? Couldn't find anything in the settings.

Thanks!

3
  • 2
    why would you want to Commented May 31, 2016 at 13:02
  • Why bother having any spacing at all? for(int i=1;i<=39;i++) - Exactly as @Shweta Goyal said, readability is key. Especially on multi-person projects Commented May 31, 2016 at 13:09
  • 1
    The "smart indent" options are highly configurable. Unfortunately, your unusual conditional operator formatting does not appear to be one of the options. You could write an extension to implement this formatting logic, or you could change your formatting style. Whichever you think is easier. Commented May 31, 2016 at 14:57

1 Answer 1

1

Although the smart indent provides beautification to code and improves readability. But if you anyhow don't want this feature, you can turn off the reformatting of code (pretty listing)

In VS2015, you can find this setting at-

Tools > Options > Text Editor > Basic > Advanced > Pretty Listing (uncheck this)

Hope this helps!

Sign up to request clarification or add additional context in comments.

2 Comments

Well, thanks for answering but I like Smart Indent being customized, I want it on but it messes up with ternary operators.
I guess there is no way to stop that. You must stop entire project's indentation in order to achieve that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.