tags:

views:

276

answers:

4
#include<iostream>
using namespace std;
class Example
{
    public:
        Example(int a,int b,int c):m_a(a),m_b(b),m_c(c)
    {  // Wrong indentation here due to the colon in above line, { should be under E
        printf("\nThe 3 argument constructor invoked\n");
    } // Wrong indentation again
    private:
        int m_a;
        int m_b;
        int m_c;
};

Hi all,

I have a little problem in gvim's indentation in the constructor initialization list in C++. I am using cindent in the .gvimrc and i am unable to solve this problem even after changing my .gvimrc a number of times.

Can some benevolent soul give me some method to set this up. I have tried changing cinoptions as well as cinwords but nothing really helped.

I have highlighted the indentation problem in the code snippet provided above.

Thanks for your patience

Regards lali

+1  A: 

Try :set smartindent, I had to disable cindent first to get it working.

Winder
No this doesn't solve the problem. Setting smartindent after disabling cindent only solves this problem, but i want cindent as well for future indentation which is not available if cindent is disabled. I have already tried this solution, thanks anyway, but i want something better.
ghayalcoder
The `smartindent` help page also recommends using `autoindent`, maybe try using both of those together instead of cindent.
Winder
A: 
Sam Post
A: 

I don't know if this is an option, but you could have a look at astyle. We use TextMate at work, and the (default?) indentation scheme is not what we want some of the time. But mostly it follows the indentation of the previous line after pressing enter or something.

The solution we use is simply piping the full source of the file through astyle (using appropriate options), and this is bound to a shortcut key. This is afaik also possible with vim.

Jan
+1  A: 
:set cino=i0
Corwin