Stop visual studio 2013 from repositioning braces on new line? - c#

When I press enter, it reposition the braces. How can I stop that? I want VS to keep automatically adding a closing brace after I type an opening brace, but I don't want it to move the brace on enter. How can I do that?

In Visual Studio 2013, you can change that option by doing the following:
Go to menu and select: "Tools|Options"
Select node "Text Editor"
Select node "C#"
Select node "Formatting"
Select node "New Lines"
Uncheck "Place open brace on new line for... " whatever you don't want the opening brace to be moved down to the next line for.
Select "OK button"
This is the automatic behavior styling. This means if you copy/paste, or complete a block, if your "format on paste" option is option, VS will restyle the pasted block. If your "format block on completion" option is on, it will restyle the block (putting the opening brace where the style demands it).
From your comments, it seems you should be asking "How do I turn off style enforcement?" or "How do I only enforce brace style on if blocks?"
You could go into "Tools|Options|Text Editor|C#|Formatting|General" and uncheck the Automatically format options to prevent the enforced styling whenever you paste, complete a block by typing }, or ;, but it won't stop all the automatic restyling in the Visual Studio editor when editing C# file types.

There isn't a setting that I am aware of to leave it on the line that you typed it (since most groups establish coding style standards that would state to put the opening brace should always be on the same line or always on the new line).
You can get VS to "forget" what it is supposed to do with a brace by moving the cursor outside of the brace block. So if you leave the Options >> Formatting setting checked (so it would normally put the brace on the next line) you can get the opening brace to stay on the same line by hitting RIGHT ARROW, LEFT ARROW, ENTER (i.e. move the cursor past the end brace, then move it back between the braces, then enter a new line).
Not what you wanted, but that's the best I can think of.

Related

Visual Studio - Space after auto filling word

recently moved over to visual studio
When I start typing a word, let's say "Tex" I get the popup with possible auto-fillings, and if I press enter, it automatically changes it to "TextBox"
The problem I have is, whenever I do that, I have to press 'space' to start typing the next word, something that get's pretty annoying if you type 10,000 words..
Is there an easy way to make the typing start one space after the autofilled word?
Thank you in advance :)
Pic1: http://prntscr.com/fbpzdq
Pic2: http://prntscr.com/fbpzlc
Yes, you can simply use the Spacebar to perform the auto-complete instead of pressing Enter. Both methods finish the completion of the word, but using the Spacebar will also add a space after the word.
It even works when using the "." character after a name; you still get the intellisense list of object members to choose from, and auto complete will magically remove the space(s) when you type a ; or closing brace }, or any other character that triggers line formatting.
Example
// This is what it looks like while typing, using Spacebar to complete the words
this .textBox1 .Text = "hello"
// And then as soon as the `;` is added, it's all fixed:
this.textBox1.Text = "hello";
And, for what it's worth, whitespace is allowed on either side of the . between an object and it's members. So even if the spaces were left as in the first example, the code still compiles and runs just fine.

Enter in text editor set cursor at begin of line instead of tabs

I have a strange behaviour with VS2015.
In C# code (the file is .cs) when I hit the enter, the cursor will always begin on position 0 of the next line. No tabs will be inserted to push the cursor to the same position of the previous line where code started.
public class Fake
{
public void Test() (here I hit enter)
{ <-- no tabs are automatic inserted before {
}
I have done: repair VS2015, Reset user Environment settings VS.
Someone an idea to reset the behaviour to default C# text editor?
Find the parameter - /ResetUserData - which Removes all user settings and makes you set them again. From http://msdn.microsoft.com/en-us/library/bb245788%28v=vs.80%29.aspx#vs05idetips_topic6
I got a similar issue here and it was about files.autoSaveDelay setting.
Issue:
After breaking line my cursor does go to the right indentation but after 1 sec goes straight to the beginning of the current line.
Cause:
So it happens because VSC (Visual Studio Code) erases any tab or spaces within a line if there is only these type of chars.
Solution
What you can do in order to solve it is either set a higher delay to files.autoSaveDelay or disable files.autoSave.

allowing to insert breakpoint in visual studio editor extension

Add Syntax Highlighting to IElisonBuffer
I follow this question and implement my visual studio editor extension.
I got everything working fine: syntax highlight, completion...but I cannot add breakpoint even thought the options was there in the right context menu (disabled)
Is there anything else I need to do to enable this feature for my editor?
Well, for the breakpoint to actually do anything, you'll need to implement a debugger (via the AD7 interfaces, etc.).
But to just get the actual breakpoint toggling working, all you need to do is implement the IVsLanguageDebugInfo interface (and optionally IVsLanguageDebugInfo2 and IVsLanguageDebugInfo3 too for more control). (I suggest you do so on the your language info object that's already implementing IVsLanguageInfo.) Don't forget to register your implementation so that VS knows about it.
ValidateBreakpointLocation() will be called when the user presses F9, etc., and in it you should set the breakpoint span to the appropriate bounds of the line (or portion of the line depending on your language, e.g. you might be in a lambda or want to highlight a statement except for any trailing comments on the line), then return VSConstants.S_OK.

Visual Studio: How to show Overloads in IntelliSense?

Once code has been written, the only way I know of to view the overloads for a method is to actually edit the method by deleting the Parenthesis () and reopening them.
Is there a shortcut key that I could press to activate this instead of having to edit my files?
For an example, please reference the ShowDialog Overload screen shot below:
With your cursor inside the parentheses, use the keyboard shortcut Ctrl-Shift-Space. If you changed the default, this corresponds to Edit.ParameterInfo.
Example:
Ctrl+Shift+Space shows the Edit.ParameterInfo for the selected method, and by selected method I mean the caret must be within the method parentheses.
Here is the Visual Studio 2010 Keybinding Poster.
And for those still using 2008.
Tested only on Visual Studio 2010.
Place your cursor within the (), press Ctrl+K, then P.
Now navigate by pressing the ↑ / ↓ arrow keys.
The default key binding for this is Ctrl+Shift+Space.
The underlying Visual Studio command is Edit.ParameterInfo.
If the standard keybinding doesn't work for you (possible in some profiles) then you can change it via the keyboard options page
Tools -> Options
Keyboard
Type in Edit.ParameterInfo
Change the shortcut key
Hit Assign
It happens that none of the above methods work. Key binding is proper, but tool tip simply doesn't show in any case, neither as completion help or on demand.
To fix it just go to Tools\Text Editor\C# (or all languages) and check the 'Parameter Information'. Now it should work
Great question; I had the same issue. Turns out that there is indeed a keyboard shortcut to bring up this list: Ctrl+Shift+Space (a variation of the basic IntelliSense shortcut of Ctrl+Space).
The command Edit.ParameterInfo (mapped to Ctrl+Shift+Space by default) will show the overload tooltip if it's invoked when the cursor is inside the parameter brackets of a method call.
The command Edit.QuickInfo (mapped to Ctrl+KCtrl+I by default) will show the tooltip that you'd see if you moused over the cursor location.
I know this is an old post, but for the newbies like myself who still hit this page this might be useful.
when you hover on a method you get a non clickable info-box whereas if you just write a comma in the method parenthesis the IntelliSense will offer you the beloved info-box with the clickable arrows.
Every once and a while the suggestions above stop working, if I restart Visual Studio they start working again though.
you mean's change overload.
just Press Shift + ↑ / ↓
Mine showed up in VS2010 after writing the first parenthesis..
so, prams.Add(
After doings something like that, the box with the up and down arrows appeared.

How to set conditional breakpoints in Visual Studio?

Is there an easy way to set conditional breakpoints in Visual Studio?
If I want to hit a breakpoint only when the value of a variable becomes something, how can I do it?
Set a breakpoint as usual. Right click it. Click Condition.
When you are using Express edition you can try this:
#if DEBUG
if( fooVariable == true )
System.Diagnostics.Debugger.Break();
#endif
if statement makes sure that in release build breakepoint will not be present.
Visual Studio provides lots of options for conditional breakpoints:
To set any of these you
Set a breakpoint.
Right-Click over the breakpoint, and in the popup menu you select an option that suites you.
These options are as follows:
You can set a condition, based on a code expression that you supply (select Condition from the popup menu). For instance, you can specify that foo == 8 or some other expression.
You can make breakpoints trigger after they have been hit a certain number of times. (select Hit Count from the popup menu). This is a fun option to play with as you actually aren't limited to breaking on a certain hit count, but you have options for a few other scenarios as well. I'll leave it to you to explore the possibilities.
You can Set filters on the Process ID, thread ID, and machine name (select Filter from the popup menu)
Just another way of doing it, (or if you are using express) add the condition in code:
if(yourCondition)
{
System.Diagnostics.Debugger.Break();
}
Set breakpoint on the line
Right clik on RED ball
Chose conditioal breakpoint
Setup condition
Writing the actual condition can be the tricky part, so I tend to
Set a regular breakpoint.
Run the code until the breakpoint is hit for the first time.
Use the Immediate Window (Debug > Windows > Immediate) to test your expression.
Right-click the breakpoint, click Condition and paste in your
expression.
Advantages of using the Immediate window:
It has IntelliSense.
You can be sure that the variables in the expression are in scope when the expression is evaluated.
You can be sure your expression returns true or false.
This example breaks when the code is referring to a table with the name "Setting":
table.GetTableName().Contains("Setting")
Create a breakpoint as you normally would, right click the red dot and select "condition".
On Visual Studio 6.0
Alt+F9!!!
Set a breakpoint as usual
Right click on the breakpoint and select Condition
You'll see a dialog that says "Breakpoint Condition"
Put a condition in the field e.g. "i==5"
The breakpoint will only get hit when i is 5.
Set a breakpoint as usual.
Right-click on the breakpoint marker
Click "Condition..."
Write a condition, you may use variable names
Select either "Is True" or "Has Changed"
Set the breakpoint as you do normally, right click the break point and select condion option and sets your condition.
Create a conditional function breakpoint:
In the Breakpoints window, click New to create a new breakpoint.
On the Function tab, type Reverse for Function. Type 1 for Line, type 1 for Character, and then set Language to Basic.
Click Condition and make sure that the Condition checkbox is selected. Type instr.length > 0 for Condition, make sure that the is true option is selected, and then click OK.
In the New Breakpoint dialog box, click OK.
On the Debug menu, click Start.
You can control when and where a breakpoint executes by setting conditions. The condition can be any valid expression that the debugger recognizes. For more information about valid expressions, see Expressions in the debugger.
To set a breakpoint condition:
Right-click the breakpoint symbol and select Conditions (or press Alt + F9, C). Or hover over the breakpoint symbol, select the Settings icon, and then select Conditions in the Breakpoint Settings window.
You can also set conditions in the Breakpoints window by right-clicking a breakpoint and selecting Settings, and then selecting Conditions.
In the dropdown, select Conditional Expression, Hit Count, or Filter, and set the value accordingly.
Select Close or press Ctrl+Enter to close the Breakpoint Settings window. Or, from the Breakpoints window, select OK to close the dialog.
Breakpoints with conditions set appear with a + symbol in the source code and Breakpoints windows.
If you came from Google, this answer might be what you are searching for.
Click Debug> New BreakPoint > Function Breakpoint
there choose the conditional Breakpoint.

Categories

Resources