3
如果vim可以在我输入空行时自动进行unindentation,但它看起来不是默认行为,这可能很有用。这对Python尤其有用,Vim可以配置为这样做吗?如何在Python中遇到空行时将vim设置为unindent?
如果vim可以在我输入空行时自动进行unindentation,但它看起来不是默认行为,这可能很有用。这对Python尤其有用,Vim可以配置为这样做吗?如何在Python中遇到空行时将vim设置为unindent?
我对自己的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
我已经尝试过,发现endresult非常讨厌。想一想:平均缩进块大约是3行,所以__continuing__代码块平均发生3次__stopping__代码块。 – orlp
当您再次按Enter键时,Vim删除空行上的缩进;尝试在没有任何插件的情况下启动vim('vim -u NONE -N')和源代码插件,直到找出哪一个引起它为止。 –
应该安装Python的缩进文件。在/ usr中寻找python.vim,或者尝试[替换版本](http://www.vim.org/scripts/script.php?script_id=974)。 –