如何自动缩进行?

Mos*_*osh 2 vim

快速新手问题.假设我在Vim中有以下代码:

void main()

{

    int i = i + 1;

    return i;
}
Run Code Online (Sandbox Code Playgroud)

我把光标放在两行代码之间的空行上.当我按i(或a)输入文本时,我希望光标缩进到正确的位置(即在"int i ..."中的i下面).有什么想法可以做到吗?

Mar*_*off 6

就像@chaos提到的那样,cindent可能就是你要找的东西.

还有autoindent,smartindentindentexpr,这些都是很好的可配置,并在记录上缩进Vim文档.

以下是它们可配置的片段:

{N    Place opening braces N characters from the prevailing indent.
              This applies only for opening braces that are inside other
              braces.  (default 0).

                cino=               cino={.5s           cino={1s
                  if (cond)           if (cond)           if (cond)
                  {                     {                     {
                      foo;                foo;                foo;