6

Here's a gif of what's happening. I am pressing Enter twice. I don't want the indentation that gets created after I press Enter the second time.

EDIT: To be more precise, I do want to keep smart indentation to match newline indentation to the current block, even when new blocks are created. What I don't understand/like is the way it is adding indentation when that block was not ever indented that far to begin with. So I don't want Visual Studio to relatively indent newlines; it's not like I want to remove automatic indentation entirely.

Hunter
  • 71
  • 1
  • 4
  • Did you try *any* research on this? First hit of a DuckDuckGO search gave me [this](https://stackoverflow.com/questions/737222/turn-off-auto-formatting-in-visual-studio#5493003). This question might probably be hammered as a dupe... – Romeo Sierra May 28 '18 at 04:04
  • That question is for VB, and Hunter wanted to know in C#. There are slight differences in the settings so it's easy to get lost in there if you don't know where to look, and the first question you search is for Visual Basic. – James Whyte May 28 '18 at 04:10

1 Answers1

12

Tools - Options - Text Editor - C# - Tabs - Indenting

Set the value to None from Smart. Bear in mind this will drop your indentation to the start of the line, no tabs or spaces until you place them in yourself. This can cause headaches in the long run having to indent yourself, so you can just disable it once you move on and go back to you automated indentation.

It's not perfect, and according to everyone that uses visual studio you aren't alone in your complaints of indentation.

Please see this question if you want to know what I mean. Very messy.

James Whyte
  • 788
  • 3
  • 14
  • Thanks. Yeah I did try that but it takes away too much useful automation. I updated my question to be more precise. – Hunter May 28 '18 at 04:21
  • I think you'd need to get down and dirty with editor level code at that point. Even then, it's simply going to be trying to read your thoughts of what scope are or should be at any point in time. In that comment block, it's simply trying to indent out to a higher level. Perhaps bite the bullet and tab out your comment so it's inline with your scope? – James Whyte May 28 '18 at 04:27
  • 1
    Is not my comment at the appropriate scope? [Here's the full picture.](https://gyazo.com/8444d28502b917361ac4fdb68c0b21d5) Could you explain the editor's logic to me? I get what you're saying about how the logic should work in general, but I still don't see how the editor isn't being arbitrary in this particular case. – Hunter May 28 '18 at 16:02
  • Terribly odd. It might be a rouge character. Try to format your document, it might fix your issue. `CTRL+K` + `CTRL+D`, or by going to the following in your toolbar. `Edit - Advanced - Format Document` – James Whyte May 29 '18 at 00:03
  • Tried that, it will format the indentation in if I don't have it, and otherwise leave it. I updated the example gif in my post, or see it [here](https://gyazo.com/4b40cc03a9d683608e2de8e1a91674bf). What I updated in the gif is now I am recreating the phenomenon in the simplest case possible I could find where it would happen. – Hunter May 29 '18 at 03:40
  • I think it has to do with your settings under `Tools - Options - Text Editor - C# - Tabs`. Can you tell me the values you have for `Tab Size` and `Indent Size`? – James Whyte May 29 '18 at 03:46
  • Wait. This is happening to me too. What on earth is going on!? :O – James Whyte May 29 '18 at 03:49
  • 1
    I think this will need to be raised with Microsoft, honestly. There is no setting I know of that could change this. Looks like the editor looks at the function definition and says 'Yeah, we need another tab here'. This is replicable with `///` XML documentation blocks, too. Indeed, it looks forward and sees the function and inserts and extra tab for no understandable reason. – James Whyte May 29 '18 at 04:02