5

I have the below settings in my .vimrc relating to Perl code folding.

When I type za to toggle folding, it works on any sub { } by just folding up the sub.

However, if I za a non-sub block (e.g. if* or for or while) it folds up the entire rest of the file, not just the block.

I just want to fold up the block. How might I achieve this?

" Perl auto-folding
set foldmethod=syntax
set foldlevelstart=3
let perl_fold = 1
let perl_fold_blocks = 1

* ifs are officially statements rather than blocks in Perl, but I would still like to fold them.

  • 1
    I think this may just be a bug in the Perl folding, but I'm not sure ... You can perhaps look at /usr/share/vim/vim74/syntax/perl.vim line 426 ... Being a Perl hacker, you might have more luck deciphering the regexps that control this :-) – Martin Tournoij Feb 23 '15 at 13:40
  • 1
    za toogles folds for the current line. I assume that the lines you are toggling on are not in any folds except for one big fold that includes the whole file. You can try set foldcolumn=12 to better visualize how folds are nested. – Matt Boehm Feb 23 '15 at 20:47
  • 1
    Doing so will help you determine whether you want to adapt your understanding to account for how things currently work or to adapt perl's folding to better fit how you want it to work. – Matt Boehm Feb 23 '15 at 20:48
1

I use below commands for folding in perl

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

I believe this should work for your case as well.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.