Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Break lines and wrapping in auto formatting of Visual Studio with ReSharper

I'm working in a C# project and using Visual Studio 2012. When Visual Studio tries to format my code, it breaks lines and make my code look difficult to read. The original code (what looks pretty nice to read for me and my team):

if (list.Any(x => x.Type == (int) EnumType.Customer)) {  } 

And when Visual Studio tries to format:

if (     list.Any(         x => x.Type ==                 (int) EnumType.Customer)) {   // Other break codes } 

There are a lot of other parts where it is breaking my code. I like auto formatting for some parts, but my question is: Is there a way to disable this break lines from auto formatting in Visual Studio?*

PS: I also have ReSharper installed.

like image 728
Felipe Oriani Avatar asked Dec 26 '12 17:12

Felipe Oriani


People also ask

How do you break a line in Visual Studio?

Use the line-continuation character, which is an underscore ( _ ), at the point at which you want the line to break. The underscore must be immediately preceded by a space and immediately followed by a line terminator (carriage return) or (starting with version 16.0) a comment followed by a carriage return.

How do I Auto Arrange codes in Visual Studio?

Auto formatting settings in Visual Studio Show activity on this post. Select the text you want to automatically indent. Click menu Edit → Advanced → *Format Selection, or press Ctrl + K , Ctrl + F . Format Selection applies the smart indenting rules for the language in which you are programming to the selected text.

How do you enable auto line breaks for long lines?

For Windows, Pressing Alt+Z will break the line. Show activity on this post. This setting will wrap your words according to your editor: viewport.


2 Answers

Solution for long lines:

ReSharper, menu OptionsCode EditingC#Formatting StyleLine Breaks And Wrapping.

And disable Wrap long lines:

Enter image description here

And it really makes me crazy!

like image 87
Felipe Oriani Avatar answered Oct 20 '22 10:10

Felipe Oriani


In ReSharper's settings, in the Languages section, you can change the formatting style of your C# code. The option you're looking to disable is something along the lines of "Indent anonymous method body." You can also look through the options to further customize the formatting style to your preference.

like image 20
Adam Maras Avatar answered Oct 20 '22 10:10

Adam Maras