How to: Wrap All Long Lines in Code

  • 2 minutes to read

Follow the steps below to configure code line wrapping and apply this format to all code in your project:

  1. Open the CodeRush menu in the Visual Studio menu bar and select the Options… item to access the CodeRush configuration options.

    HowTo_CRLF_3

  2. Configure the Right margin column size. This option allows you to specify the minimum line length for which a formatting rule is applied:

  • Open the Editor | C# | Formatting | General options page.

  • Set the Right margin column size field to 60.

    HowTo_CRLF_3

NOTE

Use the Right margin column size option with the “Wrap if long or multiline” option in the Editor | C# | Formatting | Wrapping options page.

  1. Show the right margin line in the code editor (optional):
  • Open the Editor | All Languages | Right Margin Line options page.
  • Activate the Enable Right Margin Line option.

    Enable

  1. Configure wrapping style for chained method calls and lambda expression in the Editor | C# | Formatting | Wrapping options page:

    HowTo_Wrap_4

    NOTE

    CodeRush provides numerous Formatting options to configure the code style.

  2. Click Apply to save the code style changes.

    HowTo_Wrap_4

  3. Configure the Format document code cleanup rule:
  • Open the Editor | C# | Code Cleanup options page and choose the Format document rule.

    HowTo_CRLF_4

  • Enable Apply In Action to allow CodeRush to apply this rule when you call code cleanup.

  • Enable Apply on Save and Apply Code Cleanup when saving a document options to allow CodeRush to apply this rule in code cleanup before a file is saved.

    Enable

  1. Click OK to save the configuration.

  2. Open a source code file.

  3. Run Code Cleanup:

  • Right-click the project you want to clean in the Solution Explorer and select CodeRush Cleanup in the context menu.

    CleanUpProject

or

  • Save your project file.

CodeRush applies the Format document rule in code cleanup.

HowTo_Wrapping_Result