Move Line Up|Down: Indent properly

Answered

When I move a line (or lines) up or down they keep their original indention. I have seen videos where the moved lines adapt to the proper indention. 

I search for "indent" in the preferences, but couldn't find the right spot where to change it.

For example:

echo 'Hello';
if (true) {
echo ' World';
}

becomes:

if (true) {
echo 'Hello';
echo ' World';
}

But I'd like it to be indented properly:

if (true) {
echo 'Hello';
echo ' World';
}
3 comments

Hi there,

There are Move Line Up/Down and Move Statement Up/Down actions.

  • Move Line does not change indents ... as it just moves current line/selection up or down
  • But Move Statement action adjusts indents as it checks the context -- use it

https://www.jetbrains.com/help/phpstorm/using-code-editor.html#editor_statement_select

1

Ok, thanks, although it doesn't make sense to me ;) 

0

It makes perfect sense: different actions for different usage cases. What if I do not want auto-indent as it might be wrong or it moves statements not in a way I like? In such case I simply use Move Line and adjust everything manually. For your -- just use Move Statement. P.S. Shortcuts can be changed in Keymap.

1

Please sign in to leave a comment.