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

时间:2015-02-24 14:37:15

标签: perl vim

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

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

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

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

在折叠版本中,单词"之前的哈希标记执行"已经消失了。为什么?如果这是一项功能,我该如何禁用它?作为一种解决方法,我正在编写' sub do_something ##做了一些事情 - {{{',但有没有一种干净的方式让vim只显示我输入的内容? (也许这与perl.vim有关?)

1 个答案:

答案 0 :(得分:3)

显示的内容而不是折叠的行由'foldtext'选项控制。默认情况下,使用内部foldtext()函数。 :help foldtext()解释说:

  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文件类型安装它。