Robino
Robino

Reputation: 4909

Preventing Visual Studio 2008 (C++) from removing indentation tabbing in white-space only lines

Suppose I am writing an if statement in C++ with VS2008. I'm inside a function and therefore indented (a tab from the left margin, say). I type if{, hit enter and I'm now two tabs from the marging - I'm happy :-)

I move the cursor up a few lines to copy something and then back to just under the if{. Lo and behold, my cursor is now right against the left margin and I've lost my indentation. Grumpy! >:-(

I'm wasting my time retyping tabs and it's driving me bonkers. Please help me unlock the secret setting that allows me to get on with my work.

Edit: Incidentally, whilst developing in C# I experience the desired behaviour. It's just C++ that loses the auto-indentation.

Upvotes: 2

Views: 558

Answers (2)

Joel Rondeau
Joel Rondeau

Reputation: 7586

To the best of my knowledge, there is no setting to get this to work in VS2008.
In VS2010, it does behave how you would expect.
If you can, I would recommend using VS2010. If you are doing c++-cli, you can set the project to use the .Net 3.5 framework, and then it compiles using VS2008. If you are doing vanilla c++, you can go into the project property pages, General and set the Platform Toolset to v90 to get it to compile using VS2008. Of course, you could just compile using VS2010 if that's an option for you.

Upvotes: 2

Tyler Hyndman
Tyler Hyndman

Reputation: 1400

If you view white space (Edit > Advanced > View White Space), you can see that when you press enter the tabs are not put into the file until some text is typed. When you click away, Visual Studio doesn't remember that you were indented.

A potential solution to you problem is in Tools > Options > Text Editor > C/C++ > General, you can check "Enable virtual space". This allows you to put the cursor anywhere and once you type a character it adds the tabs/spaces up to the cursor.

The option in C# that is missing from C++ is the check box "Indent block contents" in Tools > Options > Text Editor > C# > Formatting > Indentation.

Upvotes: 2

Related Questions