如何修复 vim 以正确缩进包含 Python 注释行的折叠?

2024-01-10

我将 vim 的折叠方法设置为缩进,这在编写 Python 时效果很好,除非我有注释行。例如,如果我有这段代码:

def myFunction():
    # here is my comment
    myString = "hello"
    myInt = 2

如果我将光标放在注释行上并输入“za”,我会收到一条错误消息“E490:未找到折叠”。如果我将光标放在以“myString =”开头的行上,我将得到如下折叠:

def myFunction():
    # here is my comment
+--- 2 lines: myString = "hello" -------------------------

在这两种情况下我都想得到这样的折叠:

def myFunction():
+--- 3 lines: # here is my comment -------------------------

基本上,注释行应该像其他任何东西一样对待。我通过网络搜索还没有找到答案。有任何想法吗?谢谢!


您必须将 Foldignore 设置为空。

:set foldignore=

From :help foldignore:

'foldignore' 'fdi'  string (default: "#")

    Used only when 'foldmethod' is "indent".  Lines starting with
    characters in 'foldignore' will get their fold level from surrounding
    lines.  White space is skipped before checking for this character.
    The default "#" works well for C programs.  See |fold-indent|.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何修复 vim 以正确缩进包含 Python 注释行的折叠? 的相关文章

随机推荐