Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Vim, how to avoid having "/*" be treated as comment

Vim keeps treating my perl code as comments and the auto indentation does not work.

$dump=`cp /local/*.txt .`;
if ($a == 0)
{
    if ($b == 0)
    {
        print "HELLO";
    }
}

was formatted as:

$dump=`cp /local/*.txt .`;
                  if ($a == 0)
                  {
                  if ($b == 0)
                  {
                  print "HELLO";
                  }
                  }

This is because the "/*" in the first line was treated as comment and hence Vim gives up indenting anything afterwards.

I could think of a workaround as:

$dump=`cp /local/*.txt .`; #*/;

To manually close the comment.

But is there a better way?

Thanks.

like image 438
Pan Yan Avatar asked Oct 14 '13 21:10

Pan Yan


1 Answers

You're using cindent, which is meant specifically to autoindent C code (including C-style block comments). This has no awareness that you are actually writing perl. Try smartindent instead, it seems to work better with perl. To try this, run set cindent! and then set smartindent. If this works better, you can change it in your .vimrc file.

If you're talking about the = key to indent, rather than the ident-as-you-go indentation, this is uses a separate formatter. You can change the what is used by setting equalprg. For perl, you might use set equalprg=perltidy\ -quiet to run the selected lines through perltidy.

like image 155
AKHolland Avatar answered Oct 22 '22 01:10

AKHolland