Visual Studio Formatting



-->

Use the Formatting options page to specify how elements and attributes are formatted in your XML documents. To access XML formatting options, choose Tools > Options > Text Editor > XML, and then choose Formatting.

Formatting code You can use Visual Studio to automatically format your code so that your code is written consistently. The following two commands explicitly format your code: Format Document (Edit → Advanced → Format Document, or Ctrl + K, then Ctrl + D) – Formats the entire active file.

  1. Code formatting is supported using either one of yapf or autopep8. The default code format provider is autopep8. Auto Formatting. Formatting the source code as and when you save the contents of the file is supported. Enabling this requires configuring the setting 'editor.formatOnSave': true.
  2. The default key-bindings are ctrl-k + ctrl-d for document formatting and ctrl-k + ctrl-f for formatting a selection.

Attributes

Preserve manual attribute formatting

Do not reformat attributes. This setting is the default.

Note

If the attributes are on multiple lines, the editor indents each line of attributes to match the indentation of the parent element.

Align attributes each on a separate line

Visual studio 2017 formatting

Align the second and subsequent attributes vertically to match the indentation of the first attribute. The following XML text is an example of how the attributes would be aligned:

Auto Reformat

On paste from clipboard

Reformat XML text pasted from the clipboard.

On completion of end tag

Visual Studio Formatting Settings

Reformat the element when the end tag is completed.

Mixed Content

Visual studio xml formatting

Format mixed content by default.

Visual Studio Formatting Pasted Text

Attempt to reformat mixed content, except when the content is found in an xml:space='preserve' scope. This setting is the default.

If an element contains a mix of text and markup, the contents are considered to be mixed content. Following is an example of an element with mixed content.

Visual Studio Formatting Style

See also