2011-09-21 55 views
3

如果vim可以在我輸入空行時自動進行unindentation,但它看起來不是默認行爲,這可能很有用。這對Python尤其有用,Vim可以配置爲這樣做嗎?如何在Python中遇到空行時將vim設置爲unindent?

+1

我已經嘗試過,發現endresult非常討厭。想一想:平均縮進塊大約是3行,所以__continuing__代碼塊平均發生3次__stopping__代碼塊。 – orlp

+0

當您再次按Enter鍵時,Vim刪除空行上的縮進;嘗試在沒有任何插件的情況下啓動vim('vim -u NONE -N')和源代碼插件,直到找出哪一個引起它爲止。 –

+0

應該安裝Python的縮進文件。在/ usr中尋找python.vim,或者嘗試[替換版本](http://www.vim.org/scripts/script.php?script_id=974)。 –

回答

2

我對自己的indent/python.vim進行了一些修改以在輸入第三個空行時啓用完全縮進。您可能可以根據您的需求進行調整。

diff --git a/python.vim b/python.vim 
index 0c04e81..c60c30e 100644 
--- a/python.vim 
+++ b/python.vim 
@@ -142,8 +142,14 @@ function GetPythonIndent(lnum) 
     " If not, recommend one dedent 
     return indent(plnum) - &sw 
    endif 
- " Otherwise, trust the user 
- return -1 
+ 
+  " Is user trying to break out of this function? 
+  if plnum < a:lnum - 2 
+   return 0 
+  else 
+   " Otherwise, trust the user 
+   return -1 
+  endif 
    endif 

    " If the current line begins with a keyword that lines up with "try" 
@@ -186,6 +192,11 @@ function GetPythonIndent(lnum) 
    return plindent 
    endif 

+ " Double linebreaks means we're starting a new function (probably) 
+ if plnum < a:lnum - 2 
+  return 0 
+ endif 
+ 
    return -1 

endfunction