Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 10 months ago.
The community reviewed whether to reopen this question 10 months ago and left it closed:
Original close reason(s) were not resolved
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(8)
就我个人而言,我无法说服自己在代码中乱扔标记。 我已经非常习惯(并且高效)使用缩进折叠。 加上我用空格键(见下文)打开/关闭折叠以及 zR 和 zM 命令的映射,我就如在家中一样。 非常适合Python!
这映射空格键以在正常模式下打开/关闭当前缩进折叠。 它还映射空格键以在视觉模式下创建手动折叠。 但是,如果将 Foldmethod 设置为缩进,则此方法不起作用,因此其目的是一个谜。
Personally I can't convince myself to litter my code with the markers. I've become pretty used to (and efficient) at using indent-folding. Together with my mapping of space bar (see below) to open/close folds and the zR and zM commands, I'm right at home. Perfect for Python!
This maps the spacebar to open/close the current indented fold in normal mode. It also maps the spacebar to create a manual fold in visual mode. However, this doesn't work if foldmethod is set to indent so its purpose is a mystery.
我使用 Python 的 this 语法文件。 它将折叠方法设置为语法并折叠所有类和函数,但不折叠其他内容。
I use this syntax file for Python. It sets the folding method to syntax and folds all classes and functions, but nothing else.
另一个用于折叠 Python 代码的插件。 相当简单,处理文档字符串,在 GitHub 上:
SimpylFold
享受吧!
Yet another plugin for folding Python code. Rather simple, handling docstrings, and on the GitHub:
SimpylFold
Enjoy!
Python 非常适合按缩进折叠,有点适合编写我自己的代码,我使用标记,因为它们可以按照您想要的方式压缩文档,并且可以充当一种目录。 我的 vimrc 中有这个,当我查看别人的代码时可以在两者之间切换。
Python is well suited for folding on indent, bit for writing my own code I use markers as they can crunch a document down the way you want it and can serve as a kind of a table of contents. I have this in my vimrc to flip between the two when I'm viewing someone elses code.
我真的很喜欢
python_ifold
插件。I really like the
python_ifold
plugin.在您的
.vimrc
中:然后
zM
屏蔽所有zR
以展开所有。 我还补充说:所以你可以
z1
和z2
逐渐取消缩进。In your
.vimrc
:Then
zM
to mask allzR
to expand all. I also added:So you can
z1
andz2
to unindent little by little.对我来说,理想的折叠是只折叠
class
和def
块,缩进折叠对我来说太不合口味了。 我认为一个优雅的解决方案是使用像这样的语法系统 one 提到由托马斯. 然而,这个文件旨在替换原始语法文件,并且它可能会比原始文件更旧(即该脚本没有提到 Python 3 语法)。我的解决方案是在
~/.vim/syntax
文件夹中放置一个名为python.vim
的文件,其中仅包含重要的行(取自上面的脚本):然后只需激活使用
:set Foldmethod=syntax
进行折叠。For me the ideal folding is to fold just the
class
anddef
blocks, indent folding is too much for my taste. I think one elegant solution is to use the syntax system like this one mentioned by Tomas. However, this one is meant to replace the original syntax file and it may end being older than the original (i.e. that script doesn't mention Python 3 syntax).My solution is to place in the
~/.vim/syntax
folder a file namedpython.vim
with just the important lines (taken from the above script):Then simply activate the folding with
:set foldmethod=syntax
.我真的很喜欢我为 .vimrc 编写的这个 vim 小脚本。 它映射
alt+1
来折叠第一个 python 缩进级别(类定义和函数),alt+2
来折叠第二级(类方法),以及alt+0
展开所有内容。 它确保它只折叠一层,并且不会折叠任何嵌套的子层。 您仍然可以使用za
来切换当前块的折叠。 请注意,在^[0
中,^[
是我的终端的alt
。 对 vim 脚本没有太多经验,所以请随意就该功能提出建议:)I really like this little vim script i wrote for .vimrc. It maps
alt+1
to fold the first python indent level (class definitions and functions),alt+2
to fold the second level (class methods), andalt+0
to unfold everything. It makes sure it only folds one level and doesn't fold any of the nested sub levels. You can still useza
to toggle folding for the current block. Note that in^[0
, the^[
isalt
for my terminal. Don't have a lot of experience in vim script so feel free to make suggestions on the function :)