15

I like the way Visual Studio (2008) formats C# code; unfortunately it seems it doesn't behave in the same way when writing C++ code.

For example, when I write a code in this way:

class Test {
public:
    int x;
    Test() {this->x=20;}
    ~Test(){}
};

in C# (ok this is C++ but you can understand what I mean), this part:

Test() {this->x=20;}

Will become:

Test() { this->x=20; }

This is obviously a stupid example, but there are a lot of things where putting brackets in correct position, indenting code and other things with my own hands becomes boring.

I can obviously change editor if you suggest me a good one for C++ code, I would like to find something with these features:

  • Intellisense (like vs, at least similar)
  • Custom class coloring (in C=C# they are cyan, why are they black in C++?)
  • Wordwrap (possibly)
  • Documentation when you mouse over a method/variable
  • Auto formatting (when you close a bracket like "}" in C# you'll get everything well formatted)

Obviously I can find other features, but this is what is in my mind at the moment.

Thanks for any suggestion.

CCovey
  • 799
  • 1
  • 10
  • 17
Francesco Belladonna
  • 11,361
  • 12
  • 77
  • 147
  • Fairly sure this is a duplicate, however my google-fu is letting me down and I need to go do some work, but I'm fairly certain this exact question has been asked before. – Binary Worrier Apr 09 '10 at 15:36
  • 1
    The C++ IDE has a *very* different editor. Before you spend serious money on add-ins, check out what VS2010 does. It has a completely re-written editor, maybe the IDEs will have more in common. – Hans Passant Apr 09 '10 at 16:16
  • Maybe you are right, but isn't VS2010 still in beta?When it will come out (I know is soon... I would like to know what "soon" means in this case) – Francesco Belladonna Apr 09 '10 at 16:30

5 Answers5

12

Select the code-text and press CTRL+K-F in Visual Studio - That's it :)

hB0
  • 1,977
  • 1
  • 27
  • 33
  • My 2 cents -- Having to remember to press CTRL+K-F after every change to a file is a pain. Sure it is not as bad as having to go through the code and add extra formatting in, but it is still a pain that C# coders don't have because VS automatically updates the format as they type. – Ben Dec 21 '14 at 15:51
  • well does happen with c# code as well, specially if you copy paste.. among other reasons. i also use CTRL+K-F for c# and xml/xsd as well as config files.. – hB0 Dec 22 '14 at 13:32
6

I'm using AStyle extension for VS2012 and I'm happy with it.
It's free :)

Achilles
  • 1,554
  • 1
  • 28
  • 36
5

If you look at the Tools->Options->Text Editor settings you can control some of what you want, but I don't think as much as you'd like. Instead of changing editors, if the code style is that important, why not run it through a pretty printer? Check out this thread for ideas.

Community
  • 1
  • 1
AlG
  • 14,697
  • 4
  • 41
  • 54
  • My other thought is that it may be easier to adapt to the editor than to make the editor adapt to you. I have spent a lot of time in Visual Studio and actually like its defaults. (Yes you should put spaces on the insides of your braces! heh) – dash-tom-bang Apr 09 '10 at 15:43
  • 1
    That's a good suggestion, the problem is that I would like to "auto format" my class/block/otherThings after } or ;... "UniversalIndentGUI" could work with notepad?I'll check it (but if I'm not wrong, I'll lose a lot of features that VS has) – Francesco Belladonna Apr 09 '10 at 16:33
2

You'll struggle to find a much better editor than Visual Studio for writing c++ code. You will get used to it eventually. If you really cannot cope, then take a look at Visual Assist. It is a little pricey but it will beautify your code colours.

DanDan
  • 10,462
  • 8
  • 53
  • 69
  • 2
    You are right but, for my way of thinking, writing code should be something that I like... that's why I'm looking for something like this, because after a lot of lines, you'll get bored from things like "put a space after your ; and before }" while the editor can do it for you. Visual Assist looks very nice, but the price is too high for me, I'm a student actually... – Francesco Belladonna Apr 09 '10 at 16:35
1

SlickEdit is a highly configurable editor and offers tagging functionality (what VS calls "Intellisense") that blows VS and Visual Assist out of the water. Plus there's a cool preview window that shows you the definition for the thing under the cursor, which is lightning fast (and you can turn off if you want).

I use vim these days, though, which is even more highly configurable, and I'll never go back. It's a little trickier to get configured well, though.

dash-tom-bang
  • 17,383
  • 5
  • 46
  • 62