I'm using Visual Studio 2010 + ReSharper. I there any way to modify auto-indent for methods parameters (any VS2010 or ReSharper option)?
For example:
public Topology(string name, TopologyType type = TopologyType.Initial)
{
}
If I'm pressing Enter before second parameter I get next indent:
public Topology(string name,
TopologyType type = TopologyType.Initial)
{
}
But I need next one:
public Topology(string name,
TopologyType type = TopologyType.Initial)
{
}
I found what I need in ReSharper options (Formatting Style -> Line Breaks and Wrapping), but it works only when use Clean Code -> Refactor, not when I just typing it.
Thank you.
According to documentation ReSharper can automatically reformat code only after typing semicolon or closing brace. The only way to modify auto-indent for methods parameters is to use Cleanup Code -> Reformat code.
But to simplify usage you can set Silent Cleanup Profile in the Options -> Tools -> Code Cleanup and use it with hotkey on selected code (by default Ctrl + E, F).
Related
There appears to be no option for automatic formatting, it slightly irritates me. Perhaps I have OCD:
private void someFunc() {
}
// I want
private void someFunc(){
}
I have tried looking in |options > text editor > C# > code style > formatting| ... to no avail.
In c# formatting is no entirely automatic. You need to press ctrl+k;ctrl+e to format file.
For C# code files, Visual Studio 2019 has a Code Cleanup button at the bottom of the editor (keyboard: Ctrl+K, Ctrl+E) to apply code styles from an EditorConfig file or from the Code Style options page.
Use instruction from here to setup your style
But, if there is a space or no space - you must set in your style setting.
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" ),
Just select all the text
and press (control + j)
and it will become 1 line of code
I setup find/replace for quick use with a regex expression like so:
(note: I use VS 2015, so your hotkeys may be different)
Use Ctrl+H to open quick find replace.
Make sure the "Use Regular Expressions" button is active/toggled-on, and that you are set to search in "Selection" (Not "Document" or "Entire Solution" or whatever)
Type
\s+
and a space ()
in the "find" and "replace with" boxes respectively.
Press Esc key to exit quick find/replace.
Now, as long as you don't change anything, you can select any text you want to make single line, and use the following hotkey sequence to quickly format it:
Ctrl+H (Open quick find/replace)
Alt+A (Replace any occurrence of 1 or more White Spc chars with a single space.)
Enter (Close the popup window that says "X Occurrences Found")
Esc (Exit quick find/replace and return to your code)
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*/; } }
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
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.
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
Hit Ctrl + Shift + P
Join Lines
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.
You can accomplish this using CodeMaid. The default keybinding is F3, but the command is called CodeMaid.JoinLines if you want to change it
For example:
Suppose there are three objects, Model, ModelParam, ModelParamValue
And I have such a line:
f(Model)
I would like IntelliSense to show the ModelParam and ModelParamValue options as I type "p" like this
f(Modelp)
How should I change Visual Studio's setting to accomplish this?
Also, If I type Model, there'll be the three options in the IntelliSense window, but if I hit ESC, the window would be gone and even if I type "p", the window won't come back. How should I fix this?
The reason I'm asking this is that this feature is available in SQL Server 2008, so I guess it only needs some configuration to work properly in VS.
I'm writing program using C# in VS2012.
By pressing the keycombination to bring up intellisense:
ctrl+space
When you have for example the following snippet:
void testTest() {}
void testTast() {}
int main() {
testT //press ctrl + space after this and it will bring up the 2 possibilities
testTa //press ctrl + space after this and it will fill in testTast
testt //press ctrl + space after this and it will bring up the 2 possibilities
}
Works in both Visual studio 2010 and Visual studio 2012, and very likely in other versions aswell.
Is there a way to make Intellisense(CTRL+Space) automatically open after I type a letter? Its really annoying me to have to press CTRL+Space every line of code
What you describe is the default behavior. To restore it, use:
Tools -> Options -> Text Editor -> C# (e.g.)
Statement Completion -> Auto list members: Checked
Edit:
In C++ "Auto list members" does not apply to the first identifier in an expression, that is, when the identifier could be almost anything: a global variable, a keyword, a class member, etc. It does however apply (and does work) after the ".", "->", and "::" operators.
A workaround for a very common case of desiring auto listing for class members is to use the "this->" convention in your code, which some coding standards recommend anyway. The completion list will pop up immediately upon typing "->".
Default C++ IntelliSense does not open automatically when you are typing except for after ., -> and ::. The third party commercial extension Visual Assist X does provide that behavior though.
Wondering if there is anyway way to expand/collapse the IF-ELSE code block in VS2010? Sometimes the code inside IF-ELSE is too long and I would like to hide it.
Anyway one know? Thanks a lot!
EDIT: Please be informed that I'm using #region & #endregion inside the IF-ELSE statement. Try looking for more convenient style like JScript extension does.
Go to the Options dialog box and select Text Editor, expand C/C++, and then click Formatting. Activate "Automatic outlining of statement blocks."
Source: http://msdn.microsoft.com/en-us/library/0x6hx0kx.aspx
I'm using the full version of Visual Studio 2010, don't know if this is available in the express version.
you can add regions, regions are collapsable
#region Name
if()
{
///code
}
endregion
Try surrounding the if-else with a region:
#region regionName
if()
{
#region regionName
#endregion
}
else
{
}
#endregion
You can also select the block you want to hide and press Ctrl+M,Ctrl+H
or
Select the block -> right click it -> Outlining -> Hide Selection
So
You will have a '+' on the left to hide and show it when you want.
Go to Tools -> Options -> Text Editor -> C# -> Formatting -> Indentation. Tick "Indent open and close brackets".