[英]How to set vim to unindent when meets a empty line in Python?
如果當我鍵入空行時vim可以自動執行unindentation會很有用,但它似乎不是默認行為。 這對Python特別有用,可以配置Vim嗎?
我為自己的indent/python.vim
做了一些mod,以便在輸入第三個空行時啟用完全dedent。 您可以根據自己的需要進行調整。
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.