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?
-
Related: http://stackoverflow.com/questions/236517/how-can-i-make-visual-studio-wrap-lines-at-80-characters – Patrick Jan 11 '11 at 02:25
-
1When I first started programming I felt like Pasha, however, even though I still have a wide monitor, I now like to keep things 80 columns or less for portability reasons. Also for the ability to view two code files side-by-side. – Cory Gross Apr 01 '13 at 00:49
-
Do you also keep HTML markup at 80 columns wide? I doubt it. I annoys me when my HTML breaks up in many unreadable lines. Code.. it easier to read in many lines if written with good codding practices.. – Piotr Kula May 29 '13 at 20:57
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)
- Tag Wrapping
- Formatting
- HTML
- Text Editor
- Options

- 1
- 1

- 17,411
- 10
- 63
- 88
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.
If one uses Resharper:
Resharper -> Options -> Code Editing -> C# -> Formatting Style -> Line Breaks and Wrapping -> Right margin (columns)
Edited for new version of Resharper (2018.3)
Resharper -> Options -> Code Editing -> C# -> Formatting Style -> Line Breaks and Wrapping -> General -> Hard wrap at
Details: The officical Resharper help

- 767
- 9
- 10