In my VS2010, if I type a for loop somewhere in between blocks of code, VS will automatically indent the following line (or block) of code for me when I press the final semicolon (the one just before the iterator).
This is indescribably annoying as I very, very regularly type nested for loops in between existing blocks of code. I've gotten into the habit of automatically pressing ctrl+z right after the last semicolon so it undoes the indentation.
Is there any way I can turn this feature off?
Answer:
Tools → Options... → Text Editor → C# → Formatting → Automatically format completed statement on ;
Alternate answer:
Press Ctrl+Enter before typing the for loop. This command works from anywhere within a line, and inserts a new line above the current line and puts the cursor on the new empty line. When you press ; at the end of your loop, the previous text will not be part of the line and will be unaffected by the automatic reformat.
Similarly, Ctrl+Shift+Enter inserts a new line below the current line.
Under Options -> Text Editor -> {Language of choice} -> Tabs. Set the Indenting to "None".
Related
In Visual Studio 2019, it likes to try to guess where it should put the semicolon when you hit it. Often it will jump to a completely different line or insert newlines. Every time it does anything besides append it as the next character, this is extremely disruptive, and I have to go back and fix what it broke. This is akin to the disruptive "Automatic brace completion" which always puts braces where I don't want them, but can be turned off. I can't find anywhere to turn off the semicolon behavior. Is there any way to turn this feature off?
Most of the time when the semicolon misbehaves, it's because I hit it by mistake, but rather than hitting backspace, I now have a bigger mess to clean up. And I've never had a situation where it did something extra that I wanted it to do.
Some examples, with * being the cursor location:
// between a ) and ;
Foo()*;
// inserts an extra space
Foo();* ;
// before an existing semicolon:
return null*;
// moves the old semicolon to the next line:
return null;*
;
// pressing semicolon in the middle of a multi-line function call:
string path = Path.Combine(
"C:\\",
"b"*
"filename.txt");
// moves the cursor to the end of the block and inserts a "; " before ";":
string path = Path.Combine(
"C:\\",
"b"
"filename.txt");* ;
Visual Studio 16.10 adds a new configuration option to control this:
Text Editor -> C# -> Intellisense -> Automatically complete statements on semicolon
With that checked, I get the problematic behavior described in the question. When I uncheck that option, it works as it did before.
This problem has not always been around, and I can find no option in VS or ReSharper to correct it, but when I use the mouse to place the cursor on a shortish line of code, and I place the cursor near the end of the line, in whitespace, it stays there, instead of jumping back to the last character on the line.
You can uncheck the option Texteditor -> All Languages -> General -> Enable virtual space in Visual Studio. This way your cursor will always be placed at the last character of a line when you click anywhere in the whitespace area at the end of a line.
Note however if your line ends with whitespaces you actually typed in, it will place the cursor after the last actual whitespace of that line. Use Ctrl + Left Arrow to jump to the last actual character of that line.
You can use Alt + Backspace to quickly delete all whitespaces at the end of a line.
Initial note: I'm not getting any responses over on superuser to my question, so please allow me to ask this here:
I inherited a VS solution with a bunch of unorthodox settings. I'm not at liberty to wipe out all those settings and start over. So there is 1 setting I want to change back to VS default but cannot find it.
In a normal/default VS c# environment, when you click the mouse on a line of code that hasn't been written yet (empty, no spaces, no code, no tabs), the cursor automatically positions to the beginning of where the line of code should begin. If it's just inside a foreach, if, or etc, it will indent a bit from the left edge according to tab rules, etc.
But in the weird VS settings I have, wherever I click, the cursor positions at that exact spot. So if I click on col 20 of the next line, the cursor remains at col 20 rather than auto-repositioning to col 5 or wherever it should be. This is SO annoying because I can't always eyeball where the cursor should be and I end up clicking at the end of the previous line, then hitting ENTER, at which time it goes to the next line and positions the cursor at the right place.
How can I fix this?
It is controlled by the Enable virtual space option. See Visual Studio options - Text Editor - C#. By default it is off/unchecked.
I resolved this issue by applying Sergey's suggested change (Visual Studio options -> Text Editor -> C# -> Enable Virtual Space [check]), but also enabled (Options -> Text Editor -> C# -> Tabs -> Smart).
There is a setting in Visual Studio 2010 to turn off copy and cut commands when the cursor is on a blank line and there is no selection. However, when the cursor is not on a blank line and you press ctrl+C, it always copies the entire line to the clipboard. I find this very irritating because I always highlight something first, copy it, then place the cursor where I want to paste it and press ctrl+V. However, sometimes I miss the v and hit the c, which replaces the text on the clipboard with the text of the current line and I have to start all over...
Does anyone know how to turn off copying when there is no selection, regardless of whether the cursor is on a blank line or not?
There is the option in the settings:
Go to Tools - Options -> Text Editor -> ALl Languages -> Apply Cut or Copy commands to blank lines when there is no selection
Also if you accidentally copied something into clipboard you can use following shortcut:
Ctrl+Shift+V – cycle through the clipboard ring.
EDITED:
It seems there is no option to turn of it because by default Ctrl-C is assigned to Edit.Copy command, which copies the current line if nothing is selected. However you can assign following macro to Ctrl-C and it should fix the issue:
Sub CopyOnlyIfSelection()
Dim s As String = DTE.ActiveDocument.Selection.Text
Dim n As Integer = Len(s)
If n > 0 Then
DTE.ActiveDocument.Selection.Copy()
End If
End Sub
I know this is old question, but as Macros are no longer natively supported in newer versions of Visual Studio, I thought I'd shared my new extension (cause I couldn't find any existing extensions): https://marketplace.visualstudio.com/items?itemName=KiwiProductions.CopyOnlySelection
When Visual Studio (2005) has Options -> Text Editor -> C/C++ -> Tabs -> Indenting set to Smart it will automatically indent code blocks and line up squiggly brackets, {}, as expected. However, if you hit enter inside a code block, move the cursor to another line, and then move it back, the inserted tabs are gone and the cursor is positioned all the way to the left. Is there a way to set Visual Studio to keep these tabs?
As far as I know, the only way to do that is to enter something (anything) on that line, then delete it. Or hit space and you'll never see it there until you return to that line.
Once VS determines that you've edited a line of text, it won't automatically modify it for you (at least, not in that way that you've described).
This is an annoyance to myself as well. Anytime the code is reformatted the blank lines are de-tabbed.
You might look at this: http://visualstudiogallery.msdn.microsoft.com/ac4d4d6b-b017-4a42-8f72-55f0ffe850d7 it's not exactly a solution but a step in the right direction