2012-10-04 22 views
2

我試圖讓VIM在一個新行開始這樣縮進續行:縮進續行不同,這取決於他們是否啓動或不能在新行

def foo 
    open_paren_at_EOL(
     100, 200) 

    a = { 
     :foo => 1, 
    } 
end 

的Vim 7.3的默認縮進[1]對於這些行是這樣的:

def foo 
    open_paren_at_EOL(
    100, 200) 

    a = { 
    :foo => 1, 
    } 
end 

我試圖多個基諾=值和予甚至試圖適應從[2],但沒有成功的。vim的腳本。

我的.vimrc是在這裏:

https://github.com/slnc/dotfiles/blob/master/.vimrc

謝謝!

+0

也會喜歡這個,但我缺乏解決它的技能。 –

回答

0

,你可以做些什麼來得到這種縮進的是找出其中GetRubyIndent功能的領域都與這些延續和增加返回值。因爲你給的例子,這似乎做的工作:

diff --git a/indent/ruby.vim b/indent/ruby.vim 
index 05c1e85..6f51cf2 100644 
--- a/indent/ruby.vim 
+++ b/indent/ruby.vim 
@@ -368,7 +368,7 @@ function GetRubyIndent(...) 

    " If the previous line ended with a block opening, add a level of indent. 
    if s:Match(lnum, s:block_regex) 
- return indent(s:GetMSL(lnum)) + &sw 
+ return indent(s:GetMSL(lnum)) + &sw * 2 
    endif 

    " If the previous line ended with the "*" of a splat, add a level of indent 
@@ -383,7 +383,7 @@ function GetRubyIndent(...) 
    if open.pos != -1 
     if open.type == '(' && searchpair('(', '', ')', 'bW', s:skip_expr) > 0 
     if col('.') + 1 == col('$') 
-   return ind + &sw 
+   return ind + &sw * 2 
     else 
      return virtcol('.') 
     endif 

我不能完全肯定,如果這不會打破別的什麼,但它似乎是一個安全的變化給我。如果您發現不按您想要的方式縮進的情況,您可以直接修復:在函數的限制範圍內搜索return,然後再增加一個返回的縮進&shiftwidth(或&sw)。檢查它是否有效,如果沒有,請撤消,然後繼續前進到下一個return,直到您真正找到它。

您可以分叉vim-ruby,或者您可以將indent/ruby.vim文件複製到~/.vim/indent/ruby.vim並根據需要進行更改。它應該優先於捆綁的indent/ruby.vim

如果你正在尋找一個完全不顯眼的解決方案,那將是困難的。從理論上講,您可以使用setlocal indentexpr=CustomGetRubyIndent(v:lnum)替代作爲壓頭的GetRubyIndent函數,然後定義CustomGetRubyIndent函數,該函數僅在特定情況下實現您的行爲,並委託GetRubyIndent。儘管如此,我不會推薦這麼做,但可能會變得相當混亂。

+0

謝謝安德魯,它完美的作品。你不知道你有多少擊鍵現在救了我:) –

相關問題