简体   繁体   English

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

[英]How to set vim to unindent when meets a empty line in Python?

It could be useful if vim could do a unindentation automatically when I type an empty line, but it seems it is not the default behavior. 如果当我键入空行时vim可以自动执行unindentation会很有用,但它似乎不是默认行为。 This would especially useful for Python, could Vim be configured to do so? 这对Python特别有用,可以配置Vim吗?

I made some mods to my own indent/python.vim to enable full dedent when the third empty line is entered. 我为自己的indent/python.vim做了一些mod,以便在输入第三个空行时启用完全dedent。 You may be able to adapt this to your needs. 您可以根据自己的需要进行调整。

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