Vim Folding and Perl

I decided to get function folding working today and discovered that it is relatively simple to set up unless Vim isn’t detecting your filetype correctly which it wasn’t in my case.
To get basic Folding for Perl working add
let perl_fold=1
let perl_fold_blocks = 1
to your .vimrc file and then open a .pl file and you should see lots of blue lines running across the screen. These are where the folds have been made and you should see a line count similar to
+– 24 lines: sub summit_sub {——————————–
Put the cursor on this line and press “za”. This will magically unfold the line. Pressing “za” again refolds the line.
I don’t like the perl folding defaults so I dedcided to run with the manual ones but my filetype was alway wrong when working on a modules. it was inserting c-style foldmarker ie “/*}}}*/” instead of the perl foldmarker #}}}
This was easlily remedied as follows
au BufRead,BufNewFile *.pm set filetype=perl || set commentstring=#%s
I now have folding working. Now all I need to do is decide what type of folding I prefer.

Leave a Reply

Your email address will not be published. Required fields are marked *