Moving On Up (Or Down)

03 Apr 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”.

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.

To wit:


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! :dancers: