gpt4 book ai didi

使用 Vim 折叠 Python 代码

转载 作者:太空狗 更新时间:2023-10-29 16:58:02 36 4
gpt4 key购买 nike

我试过一堆 Python 代码折叠插件,我看到这个问题被问过一次 here ,但它们似乎都不太适合以这种方式实现 Python 代码折叠:

class myClass(models.Model):
[folded code]

class Meta:
[folded code]

def __unicode__(self):
[folded code]

def save(self, *args, **kwargs):
[folded code]

所以我的问题是,是否有任何 Python 代码折叠插件可以做到这一点? 到目前为止我还没有找到,我已经尝试了很多这样的 Vim 插件已经。

最佳答案

description

Because of its reliance on significant whitespace rather than explicit block delimiters, properly folding Python code can be tricky. The Python syntax definition that comes bundled with Vim doesn't contain any fold directives at all, and the simplest workaround is to :set foldmethod=indent, which usually ends up folding a lot more than you really want it to.

There's no shortage of Vim plugins for improved Python folding, but most seem to suffer from cobbled-together algorithms with bizarre, intractable bugs in the corner cases. SimpylFold aims to be exactly what its name suggests: simple, correct folding for Python. It's nothing more than it needs to be: it properly folds class and function/method definitions, and leaves your loops and conditional blocks untouched. There's no BS involved: no screwing around with unrelated options (which several of the other plugins do), no choice of algorithms to scratch your head over (because there's only one that's correct); it just works, simply.

http://www.vim.org/scripts/script.php?script_id=3723

关于使用 Vim 折叠 Python 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7424871/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com