14

When I want to type something like

Type* name;

at some point during typing the line (as soon as I type the semicolon), VS2017 decides to auto-space to

Type * name;

After I removed the space the first time, the IDE didn't try that again for some time. The behaviour started again for some reason when I typed a type-pointer variable, but immediately typing another line like that didn't repeat the auto spacing...

After some more testing, the auto-spacing only seems to happen in a class where the first line of code after an access specifier becomes the victim if it matches Type* name;.

class Foo {
private:
    Type* name; //Becomes Type * name; after typing the ';'
public:
    Type2* name2; //Here as well
};

I don't like it. How do I end this blasphemy?

golem
  • 143
  • 1
  • 7

3 Answers3

6

Go to Tools->Options, then Text Editor-C>/C++->Formatting->Spacing and look through the options, however I do not believe that particular item is configurable.

SoronelHaetir
  • 14,104
  • 1
  • 12
  • 23
5

On Visual Studio 2019:
Tools > Options > Text Editor > C/C++ > Formatting > Spacing

Here change the "Pointer/reference alignment"
Select the option of your choice.

enter image description here

ani627
  • 5,578
  • 8
  • 39
  • 45
0

In Tools>Options...>TextEditor>C++>Formatting>Spacing>Spacing for operators>Binary operators change ticked radio button from Insert spaces before and after binary operators to Don't change spaces around binary operators.

rebusB
  • 518
  • 5
  • 19