当类型和名称在不同的行中时,Vim会严重缩进C/C++函数

mun*_*ish 7 c++ vim templates indentation

以下代码片段很好地解释了我的问题.

我想要的是:

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

int
main()
{
    ...
}
Run Code Online (Sandbox Code Playgroud)

我得到了什么(注意函数名称之前的过度缩进):

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

    int
main()
{
    ...
}
Run Code Online (Sandbox Code Playgroud)

我有set filetype plugin indent on我的~/.vimrc.

我看过这篇文章,但答案就像是学习一门新的编程语言.我是vim粉丝,但不是vim专家.有没有更简单的解决方案?

FDi*_*off 11

你所看到的是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()
Run Code Online (Sandbox Code Playgroud)

为此,您需要确保为cpp文件类型设置它.(cindent由默认的cpp缩进文件打开)

我想只需添加set cinoptions+=t0到你的vimrc即可.