在vim中的case语句中缩进块

时间:2014-05-22 17:03:41

标签: vim

我试图通过设置cinoptions让vim与GTK's coding style很好地玩,但我无法弄清楚用于案例陈述的内容。

所需:

switch (x)
  {
  case 1:
    {
      foo();
    }
  case 2:
    bar();
  }

A)我得到的(不需要):setlocal et sw = 2 cinoptions => 4,n-2,{2

switch (x)
  {
  case 1:
      {
        foo();
      }
  case 2:
    bar();
  }

B)我得到的东西(不需要):setlocal et sw = 2 cinoptions => 4,n-2,{2,= 0

switch (x)
  {
  case 1:
    {
      foo();
    }
  case 2:
  bar();
  }

有没有办法自动获得所需的缩进?

1 个答案:

答案 0 :(得分:3)

来自vim :help cino-:

                      *cino-:*
    :N    Place case labels N characters from the indent of the switch().
          (default 'shiftwidth').

        cino=                 cino=:0
            switch (x)            switch(x)
            {                     {
               case 1:            case 1:
                  a = b;             a = b;
               default:           default:
            }                     }

                                                   *cino-=*
    =N    Place statements occurring after a case label N characters from
          the indent of the label.  (default 'shiftwidth').

            cino=                 cino==10 >
               case 11:             case 11:  a = a + 1;
                   a = a + 1;                 b = b + 1;

您需要将:0添加到cinoptions

如果您想要=3下的缩进字符3,还需要设置case