Eclipse C++ formatting - c++

Is there a way to make eclipse format stuff like this:
int x;
bool hasX;
MyClass longName;
into:
int x;
bool hasX;
MyClass longName;
I think I once did it in Java Eclipse, but I can't seem to find it in the eclipse c++ format options.
Edit:
I don't have such option in my formatter

In the preference--> C++-->Code Style-->Formatter
Click the "Edit" button, in the "Indentation" tab, check the "Use spaces to indent wrapped lines".
Once this is done, pressing "Ctrl+Shift+F" in the editor will automatically align the text the way you have asked.
Hope this helps:)

Related

Visual Studio 2019 - don't insert a linebreak when opening curly braces (C++)

I want to declare a variable like this:
int foo {5};
But as soon as I open the first curly brace, VS does this instead
int foo {
}
I've spent a long time trying to find the relevant option but haven't had any luck.
Thanks.
Click "Options" in the upper toolbar, go to "text editor" in the left menu in the appeared window, choose "C++", "Formatting" and order Visual Studio to never newline such statements.
I couldn't reproduce the issue at vs2019. I suggest you could try to reset settings.
Tools->Import and Export Settings...->Reset all Settings->Next->"No, just reset settings, overwriting my current settings"->Next->General->Finish

Indenting function braces in Eclipse

I am working on a C++ project and using Eclipse as the IDE. The coding standards for the project specify indenting the initial and closing braces for a function, as in:
int main()
{
return 0;
}
Is there an option in Eclipse 4.3.1 to automatically indent this way?
Use the main menu to Navigate to Window->Preferences.
On the resulting dialog, expand your way to C/C++->Code Style->Formatter. Set Active Profile to Whitesmiths and edit to taste.
For example, it looks like you want to set Indentation size and Tab size on the Indentation tab to 2.

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?
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.
On Visual Studio 2019:
Tools > Options > Text Editor > C/C++ > Formatting > Spacing
Here change the "Pointer/reference alignment"
Select the option of your choice.
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.

Visual Studios 2013 indenting code

It's not necessary I fix this 'issue' since it's a more aesthetic thing. I was just wondering if it's possible to indent code that comes under the "public:" deceleration after indenting the deceleration itself.
So it would look like this:
class Myclass{
public:
void test(){
}
}
At the moment the void part would be directly underneath the public modifier. I have looked through the formatting setting and yet cannot find how to do this.
In visual studio open Tools/Options. In the menu on the left choose Text Editor->C/C++->Formatting. There you can change a lot of things like indentation.

Vim: autocomplete local variables/functions with clang_complete

I am new to vim and I am trying to set it up for use with C/C++. After reading about possible plugins for autocompletion I decided to try clang_complete.
I installed it and made sure it is working by using the included example file.
Completion after typing ::, -> or . works, but I just can't figure out how to get a autocompletion menu for local variables and functions defined in the same file or included via header.
Example:
void foobar();
void main()
{
foobar();
}
When typing foo in main(), would expect clang_complete to be able to complete it to foobar.
Did I miss anything when reading the clang_complete documentation or is this really not possible?
The answer to the question "how to open the autocompletion menu" is to click < C-x > < C-u > (which means firstly press ctrl and x at the same time, then ctrl and u). Then you'll se a menu of user defined auto completions which is where clang_complete's completions are. If you're as lazy as me and you want the completions to popUp automatically, install an additional plugin like AutoComplPop. You can also switch to YouCompleteMe, which I don't like but may suit you needs better.