I have to edit some perl scripts. There I can fold blocks surrounded by "{}" with

:set foldmarker={,}
:set foldmethod=marker

See Perl folding with perl_fold_blocks

Comments starts with #. They should be folded, if there is more then one consecutive lines.

In some files there are POD sequences. They start with = in the first column and ends with =cut (starting in the first column too).

Between there may be different lines starting with =.


# Start of a comment
## second line
## third line

# ...
abc(1, 3);

=over 4

=item arguments

There are ...



sub abc {
    my ($a, $b) = @_;
    # ...

So after folding there should be folded all

  • between =over 4 and =cut,
  • from sub abc { to }, too. To fold the sub works already - and
  • all from Start of a comment to ## third line.

I expect something like

+---  3 lines: # Start of a comment ---------------------------------

# ...
abc(1, 3);

+--- 12 lines: =over 4 -----------------------------------------------
+---  4 lines: sub abc -----------------------------------------------


I asked another question, where I hope to get the answere. There is an example of a session file. Folding problem with session

  • If you really want to use foldmethod=marker, then just add those markers in the regions that shall be folded Jul 8, 2021 at 10:40
  • @ChristianBrabandt - I want to be able to toggle fold with 'za' and best have an option to to close/open all. That 'za' works in foldmethod=manual too. So I can change it. But where to set the regions?
    – Andy A.
    Jul 8, 2021 at 11:33
  • I found How to fold C++-style comments in Vim? to fold c++ comments, but I'm not able to use it for perl comments.
    – Andy A.
    Jul 8, 2021 at 11:34
  • You could try syntax as a fold method; if the right groups have the fold property, it will just work
    – D. Ben Knoble
    Jul 8, 2021 at 12:18
  • so what is the problem with adding those markers for the regions you want to have folded? Jul 8, 2021 at 15:44


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.