How to automatic format code in Visual Studio

daowdos 271 Reputation points

I remember I had an automatic code formating right after I pressed ctrl+s.
Now I don't have that.

All I have is "Code Formatter" that makes a lot of commets which I don't need and when I remove those comments with "Clear Comments" it will remove my personal commets also.


Will be super glad for help here.

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,763 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,479 questions
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,625 questions
{count} votes

6 answers

Sort by: Most helpful
  1. Castorix31 82,321 Reputation points

    I have
    Ctrl + K, Ctrl + F
    to format the selected text
    Ctrl+ K, + Ctrl + D for the document :


    4 people found this answer helpful.

  2. Karen Payne MVP 35,286 Reputation points

    You may of used Format Document on Save Visual Studio extension.

    Enables auto formatting of the code when you save a file. Visual Studio supports auto formatting of the code with the CTRL+E,D or CTRL+E,F key shortcuts but with this extension the command 'Format Document' is executed on Save.

    4 people found this answer helpful.

  3. PengGe-MSFT 3,341 Reputation points

    Hi, @Elado

    Welcome to Microsoft Q&A!

    To format a selection: Ctrl+K, Ctrl+F

    To format a document: Ctrl+K, Ctrl+D

    See the pre-defined keyboard shortcuts. (These two are Edit.FormatSelection and Edit.FormatDocument.)
    You can Identify and customize keyboard shortcuts in Visual Studio.

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread

    2 people found this answer helpful.
    0 comments No comments

  4. P a u l 10,406 Reputation points

    Here's the extension I use to format documents on save:

    You should have a default Code Cleanup profile if you go to "Analyze > Code Cleanup > Configure Code Cleanup"

    If you move "Format document" from "Available fixers" to "Included fixer" (if it's not already) then press "Ok" and it should format your documents based on your preferences.

    There are a few fixers I use that are quite handy (Sort usings/Remove unnecessary usings probably the most useful to me):

    1 person found this answer helpful.

  5. AgaveJoe 26,671 Reputation points

    The Code Formatter is a 3rd party Visual Studio plugin. Read the openly published documentation to see if this feature is available?

    1 person found this answer helpful.
    0 comments No comments