1

With Vim 7.2, when a perl block is aligned using =, Multi line comments are moved as per the blocks inner alignment. But they should be placed at immediate start of the line. Is there any way to solve this.

Executing

    :%s/^\s\+=/=/g

every time is time consuming.

Example file:

 if($i==0)
 {
 $i=$i+3;
  =head
  This part can be optimised
  =cut
 print $i;
 }

After aligning (with =a{ or 9==)

   if($i==0)
  {
       $i=$i+3;
       =head
      This part can be optimised
      =cut
     print $i;
   }

Expected alignment;

   if($i==0)
   {
         $i=$i+3;
   =head
   This part can be optimised
   =cut
        print $i;
   }
  • 1
    What version of Vim are you using? What does set equalprg? say in a buffer with a Perl file? – Alexander Batischev Apr 28 '16 at 7:49
  • Version 7.2. When I entered set equalprg, it shows equalprg= (blank) – SibiCoder Apr 28 '16 at 9:02
2

Your problem was fixed with an update to runtime/indent/perl.vim for 7.4: they reworked the indentation logic for heredocs and stuff that follows it.

You can download the file and put it into ~/.vim/after/indent/perl.vim (or into correspoding global dir).

  • The comments are aligned properly. But the lines following it are also aligned to left edge of the screen. Expected is, the following lines has to be aligned based on it's parent block – SibiCoder Apr 28 '16 at 9:57
  • Ooops... I'm guilty of modifying your code (put it inside a sub.) How about this version? Seem to work here. – Alexander Batischev Apr 28 '16 at 10:09
  • Anyhow, the versions you provided work only for multiline comments outside any blocks. They aren't aligning multiline comments inside a block. Solution must be universal for any perl script. – SibiCoder Apr 28 '16 at 10:37
  • 1
    Vim doesn't align them because POD blocks can't be aligned: = should be right at the start of the line. perlpod doesn't say so quite as explicitly, stating that "All command paragraphs […] start with =" instead, but this thread at PerlMonks discusses the limitation (search for "indent", there's a few subthreads about it.) – Alexander Batischev Apr 28 '16 at 10:53

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.