问题描述
让我们考虑下面的代码示例...不要看代码,而要看缩进.
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!
推荐答案
在您喜欢的现代编辑器中选择代码,然后按 + .
Select the code in your favorite modern editor, and hit +.
这篇关于如何从代码中删除缩进?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!