Vim C / C ++ indentation does not work well when type and name are on different lines

The following code snippets explain my problem well.

What I want:

template<class T>
ostream& operator<<(ostream& out, const vector<T>& v)
{
    ...
}

int
main()
{
    ...
}

What I get (note the excessive deviation before the function name):

    template<class T>
ostream& operator<<(ostream& out, const vector<T>& v)
{
    ...
}

    int
main()
{
    ...
}

I have set filetype plugin indent onin mine ~/.vimrc.

I looked through this post , but the answer to this question looks like learning a new programming language. I'm a vim fan but not a vim expert. Is there no simpler solution?

+4
source share
3 answers

, , cino-t ( cinoptions t). , conniptions t0,

:h cino-t

                                            cino-t
    tN    Indent a function return type declaration N characters from the
          margin.  (default 'shiftwidth').

            cino=               cino=t0             cino=t7
                  int             int                        int
              func()              func()              func()

, cpp. (cindent cpp )

, set cinoptions+=t0 vimrc .

+7

, ! , :help 'cinoptions-values', .

:set cino+=t0

:

tN    Indent a function return type declaration N characters from the
      margin.  (default 'shiftwidth').

        cino=               cino=t0             cino=t7
              int             int                        int
          func()              func()              func()
+1

.vimrc:
"
ai "
set si
" C-Style" set cindent

0

All Articles