Mitch Storrie
Mitch Storrie

Reputation: 181

Visual Studio 2022 turn off auto indenting

So i upgraded to VS 2022. and anytime i add a semicolon. the whole code block gets backtabbed. does anyone know how to turn this off? getting tired of hitting ctrl z repeatedly..

Before.

Before semicolon

After

enter image description here

Upvotes: 11

Views: 15472

Answers (7)

EnderY
EnderY

Reputation: 3

In my case, I don't like auto formatting after doing paste. To close this functionality:

Tools -> Options -> type "Formatting" in search box and choose "General" section under your preferred programming language. For me: C# -> Code Style -> Formatting -> General.

Uncheck "Automatically format on paste".

Upvotes: 0

X86Inc
X86Inc

Reputation: 1

I have had this problem since the beginning even in 17.1 turning off adaptive formatting did not work however what did work was turning off ALL "Automatic Format" under tools->options->Text Editor->C#->Code Style->Formating

I turned off everything in that section!! because I can do my own formatting.

If you do want the editor to do some formatting you can customize it in the "General" "Indentation", "New Lines", "Spacing" and "Wrapping" sub branches of the Formatting section

Upvotes: 0

mcExchange
mcExchange

Reputation: 6494

In visual studio 2022 community:

  • Go to Tools -> Options -> "Generate .editorconfig file from settings"
  • Open .editorconfig in some text editor
  • Search for "indent_size" and "indent_style" and adapt them to your needs

effects are reflected without even restarting visual studio

Upvotes: 1

user2144857
user2144857

Reputation:

I'm not sure if you ever found the correct answer to your question, but I was having the same problem, and reading the other two answers led me to figuring it out. The problem is with the adaptive formatting option being turned on. To turn it off, go to

Tools -> Options -> Text Editor -> Advanced

You should see enter image description here

Uncheck 'Use adaptive formatting'

Save, and restart Visual Studio

This should do the trick for you.

Upvotes: 8

Mitch Storrie
Mitch Storrie

Reputation: 181

After consolidating code blocks to one block on the razor page... this seems to have corrected the issue. the indenting I believe may have been caused by some bug where the indenting fails due to attempting to address other formatted code. this is not really a solid answer but i did find that moving things around prevented this from occuring and this was nothing to do with any indenting settings within the tools text editor options.

Upvotes: 1

dbCoder
dbCoder

Reputation: 114

There is another option under Tools - Options

Text Editor - All Languages - Tabs.

Try to specify Tab size and indent size

Upvotes: -1

dbCoder
dbCoder

Reputation: 114

  1. Go to VS2022 Tools - Options Menu
  2. Type indent in search
  3. Look for Indentation under formatting option which appears under

Text Editor - C# - Code Style - Formatting Indentation

check / uncheck boxes to see how your code will look and save when happy

Upvotes: 1

Related Questions