ReSharper 2024.3 Help

Use Virtual Formatter

Although properly formatted code is easier to work with, there are several scenarios where code formatting might not correspond to your preferences, but reformatting the code is not an option:

  • You are reading third-party sources that have unusual formatting.

  • Your personal formatting preferences contradict formatting rules of a team-shared project that you are working on.

  • You want to avoid unnecessary changes to the source code because each change requires a review.

In such scenarios, Virtual Formatter comes in handy — it displays the source code in the editor according to your formatting preferences without actually changing its formatting.

Enable virtual formatter

  1. Select ReSharper | Options from the main menu or press Alt+R O, then choose Environment | Inlay Hints | Virtual Indenting on the left.

  2. Select Enable Virtual Formatter.

When Virtual Formatter is enabled, you can configure its preferences using the following options on the Environment | Inlay Hints | Virtual Indenting page of ReSharper options :

Show real whitespaces on top of virtual ones

Use this selector to visualize real whitespaces used in the source code.

When set to Always or When the caret is near, whitespaces affected by the Virtual Formatter are visualized with dots. In the illustration below, the code is indented with 2 whitespaces and Virtual Formatter indent is set to 6 whitespaces:

ReSharper: Virtual Formatter with visualized whitespaces

Use dedicated Virtual Formatter settings

If this checkbox is selected, Virtual Formatter will use settings defined on the Code Editing | C# | Virtual Formatting Style | Tabs, Indents, Alignment and Code Editing | C# | Virtual Formatting Style | Braces Layout options pages. Otherwise, general formatter settings will be applied.

You may want to use this option if you are working on the solution in a team, and general formatting settings are taken from the team-shared settings layer or from EditorConfig. In this case, you can configure Virtual Formatter settings to your liking without affecting the team-shared settings.

This feature is supported in the following languages and technologies:

Language: C#

Language: VB.NET

Language: C++

Language: HTML

Language: ASP.NET

Language: Razor

Language: JavaScript

Language: TypeScript

Language: CSS

Language: XML

Language: XAML

Language: Resx

Language: Build Scripts

Language: Protobuf

Language: JSON

Feature is available in C#

Feature is not available in Visual Basic

Feature is not available in C++

Feature is not available in HTML

Feature is not available in ASP.NET

Feature is not available in Razor

Feature is not available in JavaScript

Feature is not available in TypeScript

Feature is not available in CSS

Feature is not available in XML

Feature is not available in XAML

Feature is not available in Resource files

Feature is not available in build script files

Feature is not available in Protobuf

Feature is not available in JSON

Last modified: 30 July 2024