Pretty simple problem to explain: In Visual Studio 2010 SP1, I'm seeing weird indentation issues with braces when using Razor.
Here's how it looks:
<div>
<div>
<div>
<div>
@if (true)
{
<b>Hi</b>
}
</div>
</div>
</div>
</div>
That's what comes out after I do a CTRL + K, D to format it. Anyone else have this issue? What's the deal?
As long as your code is syntactically correct (i.e. no stray brackets or End Ifs without matching Ifs), Visual Studio will reformat your whole file with one key chord: Hold down the Control key and then press K, followed by D. Boom! Everything looks pretty again.
Auto formatting settings in Visual Studio Show activity on this post. Select the text you want to automatically indent. Click menu Edit → Advanced → *Format Selection, or press Ctrl + K , Ctrl + F . Format Selection applies the smart indenting rules for the language in which you are programming to the selected text.
The code formatting is available in Visual Studio Code (VSCode) through the following shortcuts or key combinations: On Windows Shift + Alt + F. On macOS Shift + Option + F. On Linux Ctrl + Shift + I.
This is a known bug in the editor.
To fix it, select Insert Spaces
rather than Keep Tabs
in Options, Text Editor, HTML.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With