Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable auto-spacing of * after a type in Visual Studio 2017?

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?

like image 803
golem Avatar asked Dec 25 '17 06:12

golem


People also ask

How do I turn off auto format in VSCode?

Enable/Disable Format On SaveOpen up VSCode Command Palette by pressing Ctrl + Shift + P. Search and select Open Settings (UI). Just start typing and it will auto-fill. Once there's a match, you can hit enter immediately, or manually click on the right option.

How do I add a space in Visual Studio code?

In VS Code, press Ctrl+P and execute ext install insert-spaces .


2 Answers

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

like image 86
ani627 Avatar answered Oct 05 '22 23:10

ani627


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.

like image 33
SoronelHaetir Avatar answered Oct 05 '22 23:10

SoronelHaetir