Using CMD+SHIFT+UP/DOWN when reordering element in an enum respects the semicolon. 😍 It's the small things! pic.twitter.com/ct6y537G6a— Zarah Dominguez 🦉 (@zarahjutz) April 3, 2019
I tweeted that this morning after rediscovering CMD+SHIFT+UP. I have known about this shortcut for a while, but I guess I haven’t had reason to use it until lately.
And then I remembered a variation of this shortcut that would literally “move things don’t care”.
EDIT: (versus SHIFT+ALT+UP/DOWN which just moves the line regardless of context) pic.twitter.com/zOtMUky9DC— Zarah Dominguez 🦉 (@zarahjutz) April 3, 2019
This being IntelliJ, these actions work on more than just properties. They work for basically anything in your code that has a scope – individual lines, functions, classes even!
There are two main movement actions, move statement and move line. Depending on what you want to do, each of these have their own benefits.
Moving a statement means that the IDE will respect the context within which that particular element exists. In the case of a single line of code, this means maintaining its current scope. What this means exactly is – if a line is inside a function, using CMD+SHIFT+UP/DOWN will never move it out of the function.
But this line wants to move to another function! It says so itself! This is when CMD+ALT+UP/DOWN comes in handy:
This shortcut is really handy when reordering or refactoring functions:
I leave it as an exercise for the reader to see how the shortcut behaves with classes. Get moving and stop copy-pasting!