繁体   English   中英

如何在Python中遇到空行时将vim设置为unindent?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM