Can you set Visual Studio's "smart indent" to not remove tabs in blank lines? - visual-studio-2005

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

Related

Visual Studio 2015 - arbitrary cursor position on empty 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).

Visual Studio 2013 Ultimate: Caret goes to wherever the mouse clicked

my VS2013 is configured at C# layout. Whenever I click an empty space in a file, say somewhere far right to a line of code that has ended well before, the caret moves where I click and spaces are inserted between the last character of the current line and the caret, regardless the fact that the indent settings are at "Keep tabs".
This is annoying to me. Could anyone tell me how to fix this? When I click an empty space after a line, I expect the caret goes to the right of the last character of the line.
Sounds like Virtual Space. Turn it off using Tools -> Options -> Text Editor -> All Languages (or your chosen language) and uncheck Enable Virtual Space.

Sublime behavior like in VS

How to do same behaving in Sublime Text as in Visual Studio, when using column selection
for example if there is a line break in a text, the cursor in Sublime go to beginning of a line
And this is behavior in Visual Studio desired behavior
Thanks
While you may want this functionality for other reasons, it seems like you are using it to adjust the indentation of code blocks. Fortunately, there is a much easier way of doing this. Select the text for which you want to change the indentation, then press Ctrl] to increase the indentation (move block right), or Ctrl[ to decrease indentation (move block left). You can also increase indentation by selecting the desired lines and hitting Tab, and using ShiftTab to decrease it. The one place I can think of where multiple selections would come in handy is if, for some reason, you need to indent/dedent by fewer spaces than are in your tab stop. For example, if I have some code that's indented 3 spaces, and I want to change it to 4 (using the Indent Using Spaces setting in the View -> Indentation menu), I would use a multiple selection to put a cursor on each line, then use Space or Backspace to adjust spacing appropriately.

How to automatically keep the smart indent in visual studio

I don't quite know how to phrase this question, but basically what happens is:
if i smart indent in visual studio, then click somewhere else on the page or even on the exact same line that has the smart indent, it then goes away, as if I'd had no indenting at all, not even block indenting.
It just puts the cursor/insertion point at the very beginning of the line.
EDIT: BTW I recently formatted my computer and I'm almost certain this wasn't the case before, I'm guessing it's a setting, but I've been fiddling around with all the settings trying to change this, but I can't.
Open Tools->Options. Navigate to Text Editor on the LHS. Select the source type (C++, VB, etc.). Open the tree view node and select Tabs. There, on the RHS you'll find your option

Disable auto-indent certain items in Visual Studio 2005?

I don't mind most of the way that VS2005 auto-indents (or auto-formats) my C++ code, but certain items I don't want it to automatically indent. Like #define statements for example. It takes them and shoves them all the way to the left side of the screen, no matter how deep into my scope I type them. That's really really annoying.
Is there some way to alter this behaviour, besides completely disabling auto-indent/format?
If you have only a few examples you want to change (and don't mind re-correcting the indentation when there are whole section or file reformats), you can change the indentation to what you want, then move off the line.
The formatted indentation will return, but you can Undo (Ctrl+Z) and the indentation you want will return. (Note I haven't actually tested this in the C++ editor.)
As long as you don't mind "correcting" the indentation every time you edit the line (and the other times the whole section is reformatted), this allows you to have some lines alternately indented.
Try go to Options -> Text Editor -> C/C++ -> Tabs -> Indenting and change it to Block. When selected, new lines are automatically indented. The insertion point is placed at the same starting point as the preceding line.

Resources