2011-11-22 167 views
3

在vim(例如7.3)中,我如何使用/修改cindentsmartindent選項或以其他方式增加我的.vimrc,以自動縮進大括號內的大括號,以便與第一個「單詞「(後面定義)直接在開頭(之前?vim indentation括號內括號

fN選項看起來很有希望,但在內置小括號內似乎被(N選項覆蓋。從:help cinoptions-values

fN Place the first opening brace of a function or other block in 
     column N. This applies only for an opening brace that is not 
     inside other braces and is at the start of the line. What comes 
     after the brace is put relative to this brace. (default 0). 

     cino=   cino=f.5s  cino=f1s 
      func()   func()   func() 
      {     {     { 
       int foo;   int foo;   int foo; 

當前的行爲:

func (// no closing) 
     // (N behavior, here N=0  
     { // (N behavior overrides fN ? 
     int foo; // >N behavior, here N=2 

,同時我祝願:

func (// no closing) 
     // (N behavior as before 
{ // desired behavior 
    int foo; // >N behavior still works 

我所要求的是不同fN因爲fN對齊到流行縮進,並且我想要對齊任何直接在op之前的C++ nested-name-specifier付民(,像

code; f::g<T> (  instead of   code; f::g<T> (
     {         { 

如果沒有nested-name-specifier,我想它匹配(本身。也許匹配一個nested-name-specifier太複雜了,或者也許有另一個語法的部分,這更適合於這種情況。無論如何,對於我的典型用例,我認爲如果{與最內部未封閉的((含)之間的最大字符序列的第一個非空白字符對齊,該字符不包含任何分號或左卷大括號}

順便說一句,我試圖在vim7.3中自動縮進各種std::for_each(b,e,[]{});構造時遇到了這個問題。謝謝你的幫助!

+0

嘗試'設置nocindent',爲我工作 - !但我有還有smartident和autoindent開啓 – Zaffy

回答

0

不確定是否有{自動,智能,c}縮進功能可以按照您的要求做。我做了這可能給一些啓示的映射:

inoremap ({ <esc>T<space>y0A<space>(<cr><esc>pVr<space>A{ 

缺點是,你可能需要做的不是「T」聰明的東西,回到過去的標識符(你可以使用與年初「?」一個正則表達式),它會破壞你的默認寄存器,並且如果你的標識符在paren之前是在你開始行的時候你必須做的({'你自己。這個概念是跳回到標識符之前,複製到該行的開頭,粘貼到下一行,並用空格代替每一個角色

好運