如何从代码中删除缩进? [英] How To Remove Indents From Code?

查看:239
本文介绍了如何从代码中删除缩进?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们考虑下面的代码示例...不要看代码,而要看缩进.

Lets consider this example of code... Don't look at code, but at indents.

        protected function _hashPassword( $password, $salt, $nuts = '' ) {

            if ( $nuts === '' ) {
                $nuts = Kohana::config( 'a11n' )->nuts;
            }


            $password =
                sha1(
                    $password
                    . $salt
                    . $nuts
                );


            return $password;

        }

它取自更大的源代码.如您所见,它缩进了2个标签.我想以某种方式删除缩进而不使用输入.不知何故.

It's taken from much bigger source code. As you can see, it's indented by 2 tabs. I want to somehow remove indent from it without using typing. Somehow.

如果我使用编辑器内置的替换"功能并删除这两个选项卡,如...

If I use in-editor build-in 'Replace' function and remove those two tabs like...

我得到这样的东西(不是在所有情况下,但几乎是)...

I get something like this (not in all cases, but almost)...

protected function _hashPassword( $password, $salt, $nuts = '' ) {

    if ( $nuts === '' ) {
$nuts = Kohana::config( 'a11n' )->nuts;
    }


    $password =
sha1(
    $password
    . $salt
    . $nuts
);


    return $password;

}

这是因为同一行上只有两个以上的标签,并且替换了所有4个标签.

It's because there are more than only two tabs on one line and it replaces all 4 tabs.

我正在寻找足以删除缩进的强大正则表达式!也许还有其他解决方案?只是不建议编写没有缩进的代码!

I'm looking for regular expression that's powerful enough to remove indent nicely! Maybe there are any other solutions? Just don't suggest to write code without indents!

推荐答案

在您喜欢的现代编辑器中选择代码,然后按 Shift + Tab .

Select the code in your favorite modern editor, and hit Shift+Tab.

这篇关于如何从代码中删除缩进?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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