2015-04-23 39 views
1

我cinoptions括号是如下因素:缩进语句只没有在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不以任何特殊方式缩进大小写?

回答

0

Finaly做它自己,使用在内部缩进方法:

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(\".\")) 

它还挺具体到我的编码风格(外壳必须跟一个空格)