为什么vim不能正确缩进我的Perl代码? [英] Why is vim indenting my Perl code incorrectly?

查看:159
本文介绍了为什么vim不能正确缩进我的Perl代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Perl中有一个子程序,应该像这样缩进:

I have a subroutine in Perl that should be indented like this:

sub GetFiles 
{
    my $pwd = shift;
    my @input = @_;
    my @returned;

    my @DirectoryContent = &GetContentInformation(@input);

    foreach (@DirectoryContent) 
    {
        my %current = %{$_};

        if ($current{'info'} =~ /<DIR>/) 
        {
            my $RecurseDir = &GetRecurseDir($pwd, \%current);
            push(@returned, &GetFiles($RecurseDir, 
                    &GetDirectoryContents($RecurseDir)));
        }
        else 
        { 
            # clean up the data
            my $size = $current{'info'};
            # filesize will be in number of bytes
            # remove file separators
            #$size =~ s/,//g; 
            my $extension = &GetFileExtension($current{'name'});
            delete($current{'info'});
            $current{'size'} = $size;
            $current{'extension'} = $extension;
            # push(@returned, \%current);
        }
     }
     @returned;
}

但是当我按=%(是的,cindent处于打开状态)并将光标放在子例程块的起始括号上时,它会像这样缩进:

But when I press =% (yes, cindent is on) with the cursor on the starting bracket of the subroutine block, it indents it like this:

sub GetFiles 
{   
    my $pwd = shift;
    my @input = @_;
    my @returned;

    my @DirectoryContent = &GetContentInformation(@input);

    foreach (@DirectoryContent) 
    {
        my %current = %{$_};

        if ($current{'info'} =~ /<DIR>/) 
        {
            my $RecurseDir = &GetRecurseDir($pwd, \%current);
        push(@returned, &GetFiles($RecurseDir, &GetDirectoryContents($RecurseDir)));
    }
    else 
    { 
        # clean up the data
        my $size = $current{'info'};
        # filesize will be in number of bytes
        # remove file separators
        #$size =~ s/,//g; 
        my $extension = &GetFileExtension($current{'name'});
        delete($current{'info'});
        $current{'size'} = $size;
        $current{'extension'} = $extension;
        # push(@returned, \%current);
    }
}
@returned;
}

为什么要这么做?我该如何解决?

Why does it do that? How can I fix it?

应该注意的是,我在Windows上使用的是gvim 7.3.

It should be noted that I am using gvim 7.3 on Windows.

推荐答案

也许这是神奇的想法,但…我曾经有过:

Maybe this is magical thinking, but … I used to have:

filetype plugin on
filetype indent on 

在我的_vimrc中(在Windows XP上,自动编译的gvim,各种版本),我会在Perl,LaTeX和HTML文件中遇到各种有趣的缩进问题.

in my _vimrc (on Windows XP, self-compiled gvim, various versions), and I would get all sorts of interesting indentation problems in Perl, LaTeX, and HTML files.

现在,我有

filetype indent on 
filetype plugin on

,一切似乎都是枯燥的. YMMV.

and everything seems to be hunk-dory. YMMV.

此外,我强烈建议安迪·莱斯特(Andy Lester)的vim-perl .

这篇关于为什么vim不能正确缩进我的Perl代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆