,你可以做些什麼來得到這種縮進的是找出其中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
。儘管如此,我不會推薦這麼做,但可能會變得相當混亂。
也會喜歡這個,但我缺乏解決它的技能。 –