Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change line length in Visual Studio 2010

I like to keep a lot of code on one line. But, when I hit Ctrl K, Ctrl D to format the source code, it breaks the code lines. Is there a setting in Visual Studio, or a registry hack that I can do to increase the max line length?

like image 389
PBG Avatar asked Jan 11 '11 01:01

PBG


People also ask

How do I set line length in Visual Studio code?

In VSCode, go 'Code -> Preferences -> Settings' and search for "python formatting black args". A few notes about line lengths in Python: PEP8 recommends a line length of 79 characters (72 for docstrings) Black sets line lengths to 88 characters by default.

What is Max line length?

Traditional line length research, limited to print-based text, gave a variety of results, but generally for printed text it is widely accepted that line lengths fall between 45 and 75 characters per line (cpl), though the ideal is 66 cpl (including letters and spaces).


3 Answers

For me, I had to apply Patrick's suggestion, as well as the following:

  • Tools
    • Options
      • Text Editor
        • HTML
          • Formatting
            • Tag Wrapping
              • Wrap tags when exceeding specified length (uncheck, or adjust length)

enter image description here

like image 119
Brad Werth Avatar answered Oct 18 '22 18:10

Brad Werth


This setting can be adjusted by opening Tools, Options, Text Editor, C#, Formatting, Wrapping

In the view you have a setting called "Leave block on single line". If you check it, code will stay on one line.


Edit: The above option will only work for blocks though. There's no way using vanilla Visual Studio to change the wrapping for "any line" (and I'm not aware of any registry hack unfortunately).

Using Resharper, you can set the number of columns that the text editor should consider when wrapping lines, and you can also determine if lines should or should not break. Details can be found in this answer by hmemcpy.

like image 16
Patrick Avatar answered Oct 18 '22 18:10

Patrick


If one uses Resharper:

Resharper -> Options -> Code Editing -> C# -> Formatting Style -> Line Breaks and Wrapping -> Right margin (columns)

enter image description here


Edited for new version of Resharper (2018.3)

Resharper -> Options -> Code Editing -> C# -> Formatting Style -> Line Breaks and Wrapping -> General -> Hard wrap at

enter image description here

Details: The officical Resharper help

like image 13
Motlicek Petr Avatar answered Oct 18 '22 19:10

Motlicek Petr