Reputation: 24325
Is there a keyboard shortcut or fast way to change the code below to a single line in Visual Studio 2013? I also have ReSharper installed.
Multi
new XElement("Option",
new XAttribute("Name", "FileDelete"),
"1"
),
Single
new XElement("Option", new XAttribute("Name", "FileDelete"),"1" ),
Upvotes: 24
Views: 31384
Reputation: 1389
For VS2019, default binding is set to Shift
+ Alt
+ L
+ J
Or you could rebind this to something else by going to Tools -> Options -> Keyboard -> search for 'join'
Rebind Edit.JoinLines
action to something like (Text Editor) Ctrl + J
then press Assign
Upvotes: 15
Reputation: 2485
For me doing Ctrl
+ J
opens the Linux terminal and does not format multiple lines to one line.
This is the fastest way on Linux
Ctrl
+ Shift
+ P
Upvotes: 2
Reputation: 90
You can accomplish this using CodeMaid. The default keybinding is F3, but the command is called CodeMaid.JoinLines
if you want to change it
Upvotes: 0
Reputation: 852
You can change your VS settings to automatically format code in whatever way you want, then select and retype any line/block-ending character (';' or '}') after the text you want formatted and VS will format it for you.
Upvotes: 0
Reputation: 480
Just select all the text
and press (control + j)
and it will become 1 line of code
Upvotes: 14
Reputation: 562
I setup find/replace for quick use with a regex expression like so:
(note: I use VS 2015, so your hotkeys may be different)
\s+
)I use this all the time after visual studio does things like implementing interfaces to turn stuff like
public SomeType SomeProperty {
get {
throw new NotImplementedException();
}
set {
throw new NotImplementedException();
}
}
into stuff like
public SomeType SomeProperty { get { return someField; } set { /*Some Simple Set Code*/; } }
Upvotes: 10
Reputation: 282
To make it with ReSharper, you should uncheck the option "Keep existing line breaks" in ReSharper/Options/Code Editing/C#/Formatting style/Line Breaks and Wrapping.
Or just add this line into your .dotSettings
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_USER_LINEBREAKS/@EntryValue">False</s:Boolean>
Then you could format your code using Code Cleanup Tool (default shortcut is Ctrl+Alt+F) or just by typing semicolons or braces.
Upvotes: 4