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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With