perl - 为什么 vim 折叠中第一个哈希标记消失了?

标签 perl vim

我正在使用手动折叠来编写 Perl 程序。这是一个典型的折叠:

sub do_something # does something --{{{
{
    # perl code here
} # --}}}

折叠时,这四行显示如下:

+-- 4 lines: sub do_something does something ----------------------------

在折叠版本中,“does”一词之前的哈希标记消失了。为什么?如果这是一项功能,我该如何禁用它?作为解决方法,我正在写 'sub do_something ## does some --{{{',但是有没有一种干净的方法可以让 vim 仅显示我输入的内容? (也许这与 perl.vim 有关?)

最佳答案

显示什么而不是折叠线由'foldtext'选项控制。默认情况下,使用内部 foldtext() 函数。 :helpfoldtext() 解释:

  The returned string looks like this:
      +-- 45 lines: abcdef
  The number of dashes depends on the foldlevel.  The "45" is
  the number of lines in the fold.  "abcdef" is the text in the
  first non-blank line of the fold.  Leading white space, "//"
  or "/*" and the text from the 'foldmarker' and 'commentstring'
  options is removed.

如您所见,这是 Vim 减少困惑的启发式方法。要将其关闭:

  1. 您可以清除'commentstring';它仅用于添加手动折叠标记(某些注释插件可能依赖它作为后备),方法是将 :setlocal commentstring= 放入 ~/.vim/after/ftplugin/perl .vim.
  2. 您可以编写自己的折叠函数(:help Fold-foldtext 中的示例和说明),然后全局安装或仅针对 Perl 文件类型(如上面的替代方案)。

关于perl - 为什么 vim 折叠中第一个哈希标记消失了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28698570/

相关文章:

vim - 带有 NERDComment 插件和重新映射的领导者的自定义键?

Vim:如何更改/选择函数名称

comments - VIM : Trouble mapping <c-/> and re-selecting visual selection?

regex - 在 Perl 字符串中匹配美元符号

xml - 无法使用 Homebrew perl 5.32 在 M1 Mac 上安装 XML::Parser

php - @_ -1 在 Perl 中是什么意思?

image - Image::ValidJpeg 和内存文件的段错误

perl - 在 Perl 中使用 Mechanize 响应下载不正确的文件

vim - 发现 Vim 退出状态的原因

Vim - 如何使您自己的映射可重复?