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';
}
2
9 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
Avatar
Permanently deleted user

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

1

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.

0
Avatar
Permanently deleted user

I agree with Sam: there's a big difference between Move Statement and Move Line Up/Down, and Move Statement doesn't work exactly as I'd like it to.

I think VS Code's implementation of this is pretty much perfect. There's no actual reason to want to move a line and keep the original indentation.

4

I agree with Sam: there's a big difference between Move Statement and Move Line Up/Down, and Move Statement doesn't work exactly as I'd like it to.

Could you please describe this in a bit more detail? With a snippet when Move Statement doesn't behave as you'd expect? Thanks!

0
Avatar
Permanently deleted user

Eugene Morozov there you go: https://imgur.com/a/jg2hUIC

As you can see, Move Statement Up moved the entire statement, when in fact all I wanted to do was to move up the matchQuery parameter's line.
As written in the comment, VS Code would deindent that line automatically, but WebStorm does not.

1

Even though I don't quite get why would you need to move one argument outside the argument list, it seems to be a valid request.
Could you please push it to our issue tracker? https://youtrack.jetbrains.com/newIssue?project=IDEA
(To IDEA because it's a platform feature not specific to PHP or JS)

1
Avatar
Permanently deleted user

I agree that this specific case makes less sense, but a more relevant one would be to move the argument into an object argument.
Will do.

1

Move statement in c# can not move line by line , it skips lines (like bracket, or if block) ,so I can't do move line and auto indent like other IDE ?

0

Please sign in to leave a comment.