Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2010 Code Formatting in .CSHTML - Improper Indentation

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?

like image 434
Adam Terlson Avatar asked Jun 07 '11 14:06

Adam Terlson


People also ask

How do I fix format in Visual Studio?

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.

How do I check indentation in Visual Studio?

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.

How do I arrange code in Visual Studio?

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.


1 Answers

This is a known bug in the editor.

To fix it, select Insert Spaces rather than Keep Tabs in Options, Text Editor, HTML.

like image 176
SLaks Avatar answered Sep 28 '22 12:09

SLaks