我正在使用手动折叠来编写 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 减少困惑的启发式方法。要将其关闭:
- 您可以清除
'commentstring'
;它仅用于添加手动折叠标记(某些注释插件可能依赖它作为后备),方法是将:setlocal commentstring=
放入~/.vim/after/ftplugin/perl .vim
. - 您可以编写自己的折叠函数(
:help Fold-foldtext
中的示例和说明),然后全局安装或仅针对 Perl 文件类型(如上面的替代方案)。
关于perl - 为什么 vim 折叠中第一个哈希标记消失了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28698570/