Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/157.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Vim缩进C/C++;当类型和名称在不同的行中时,功能不好_C++_Templates_Vim_Indentation - Fatal编程技术网

C++ Vim缩进C/C++;当类型和名称在不同的行中时,功能不好

C++ Vim缩进C/C++;当类型和名称在不同的行中时,功能不好,c++,templates,vim,indentation,C++,Templates,Vim,Indentation,下面的代码片段很好地解释了我的问题 我想要的是: template<class T> ostream& operator<<(ostream& out, const vector<T>& v) { ... } int main() { ... } 模板 ostream&operator您可以在.vimrc: “自动缩进 设置ai “智能缩进 设置si “C型缩进 设置cindent您看到的是cino-t(cinopt

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

我想要的是:

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

int
main()
{
    ...
}
模板

ostream&operator您可以在.vimrc:
“自动缩进
设置ai
“智能缩进
设置si
“C型缩进

设置cindent

您看到的是
cino-t
(cinoptions设置t)的效果。您需要确保连接包含
t0
,以使参数与左边距齐平

From
: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中就足够了。

正如我所猜测的,这有一个非常简单的解决方案!在激励自己阅读
: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()

这看起来更像是一个bug,你应该向vim报告,而不是在这里回答一个问题。看这里:即使它是bug,这肯定是成千上万的程序员都遇到过的。如果它是bug,我认为现在应该修复了。/你试过打开
cindent
?在我的经验中,它在类似C的语言中工作得更好。在如果你的
cinoptions
。我的是:
g0、t0、h1s、i0
,我没有你观察到的奇怪缩进。你可能有一个(英尺)混乱其值的插件。你可以看到它在哪里被更改,使用
:verbose set cinoptions?
@Kevin:我以为
文件类型缩进
为C类型文件打开了
cindent
。是的,我找到了答案,我自己刚刚发布了答案,碰巧与此答案几乎相同。:p
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()