2015-04-23 65 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(\".\")) 

它還挺具體到我的編碼風格(外殼必須跟一個空格)