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

标签 python vim

我将 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=

来自 :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|.

关于python - 如何修复 vim 以正确缩进包含 Python 注释行的折叠?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8993455/

相关文章:

python - 更新现有的 virtualenv 以使用 Python 3.6

python - 使用自定义层加载 Keras 中保存的模型,预测结果不同?

java - 带有 Jython 的 Eclipse 不理解 Java 导入

macos - vim ctrlp 插件加载我电脑中的所有文件而不是当前目录

python - 导入错误 : Pillow 3. 3.1 和 Python 2.7 和 El Capitan 操作系统

python - TensorFlow 专家组合

linux - VIM:替换当前 C/C++ 函数中所有出现的单词

linux - 在 vim 中插入文本会导致每行右移

vim - 搜索时执行文件的 "skip bottom, jump to the top"

python - 如何在 Vim 中转置文件中行和列的内容?