在 vim cindent 中仅在不带大括号的情况下缩进语句

Indent statement after case only without braces in vim cindent

我的选项如下:

:set cinoptions={1s,t0,f0s,g0,i0,(0,=0

它适用于包含大括号的 case 语句,但不适用于未加括号的 :

switch(foo)
  {
  case(0):
    {
    ...
    break;
    }
   case(1):
   ... <-- should be indented
   break;
  }

我需要 {1s,因为我的所有代码都需要像这样格式化,如果我删除 =0,我会得到这个。

switch(foo)
  {
  case(0):
      {
      ...     <-- should not be idented so much
      break;
      }
   case(1):
     ... 
   break;
  }

有什么方法可以指定 vim 不以任何特殊方式缩进大小写吗?

终于自己完成了,使用内部缩进方法:

function Indent(line)
    " Store current pos
    let l:indent = cindent(a:line)
    let l:lineprec = a:line - 1
    let l:linefirst = split(getline(a:line), " ")[0]
    if l:linefirst ==# "{"
      let l:case = split(getline(l:lineprec), " ")[0]
      if l:case ==# "case"
        let l:indent = indent(l:lineprec) + &shiftwidth
      endif
    endif
    return l:indent
endfunction

在 .vimrc 中添加:

:set indentexpr=Indent(line(\".\"))

它有点特定于我的编码风格(大小写后必须跟一个 space)