ChatGPT解决这个技术问题 Extra ChatGPT

IntelliJ IDEA: Move line?

I really like IntelliJ IDEA's "Move statement" shortcut (Ctrl + Shift + ↑/↓). However -- I am not sure if this is a bug releated to ActionScript editing only -- move statement is not always what I want and sometimes it is not correct when editing AS code.

So I just want to move a block of lines up/down. The Eclipse shortcut is Alt + ↑/↓ and does not move statement-wise. Is there an equivalent in IntelliJ IDEA?


J
Jan Gerlinger

Open Setings -> Keymap then search for "move line" via the upper right searchbox.

Under the Code folder you'll see:

Move Statement Down

Move Statement Up

Move Line Down

Move Line Up

The actions you're looking for are (as you may guess) the move line actions.


On Mac I use alt+shift+up/down to move a line. However, the indentation of the line is kept and is not adjusted according to the indentation of the new scope. Is there a way to fix that?
On Ubuntu I use alt+shift+up/down to move a line and that works fine.
I still prefer googling. I got my answer faster that way. :-D
BTW, move statement can't move a line out of its function, while move line could.
@user218867 Nope. Move Statement re-indent the selection, but Move Line not.
s
slashnick

As other people have said this is already available as a command. You can configure the short cut to your liking, but by default (at least in IntelliJ 10) it is bound to ALT + SHIFT + ↑ and ALT + SHIFT + ↓


I know this is from a while ago, but CTRL + SHIFT + UP/DOWN will obey tab structure as the line moves in the editor. This is especially useful when the code moves through various scopes, as a lot of programmers (all?) use different indentation per scope.
A
Abdul Rehman Kaim Khani
R
Radadiya Nikunj

Please find some useful shortcut for IntelliJ:

(1) IntelliJ Debugger

Step over (Go To next Step or line) : F8

Step into (Go into function) : F7

Smart step into : Shift + F7

Step out : Shift + F8

Run to cursor : Alt + F9

Evaluate expression : Alt + F8

Resume program : F9 [Mac = Cmd + ALT + R]

Toggle breakpoint : Ctrl + F8 [Mac = Cmd + F8]

View breakpoints : Ctrl + Shift + F8 [Mac = Cmd + Shift + F8]

(2) Open Specific File

Ctrl + Shift + N

(3) Open All Methods Implemented in class

Open specific class and press,

Ctrl + F12

(4) Go to Specific Line Number

Ctrl + G

(5) Method Implementation and Declaration

Declaration : Ctrl + B

Implementation : Ctrl + Alt + B

Response Type Declaration : Ctrl + Shift + B

Super class override Method : Ctrl + U

(6) Reformate Code

Ctrl + Alt + L

(7) Import relevant class

Click on relevant class (Red color field) and press,

Alt + Enter

Select valid class as per requirement

(8) Hierarchy of method calls

Select specific method and press,

Ctrl + Alt + H

(9) Comment In Code

Single Line : Select specific line and press, Ctrl + /

Multiple Line : Select Multiple Line and Press, Ctrl + Shift + /

(Note : Same operation for uncomment the code)

(10) Display Line Number

Hit Shift twice > write "line" > Show Line Numbers (the line doesn't have the toggle)

View > Active Editor > Show Line Number

(11) Code Selection

Full class selection : Ctrl + A Method Selection : Select Method Name and press, Ctrl + W

(12) Basic Code Completion

To complete methods, keywords etc press,

Ctrl + Space

(13) Code Copy and Paste

Copy : Ctrl + C

Paste : Ctrl + V

(14) Search Operation

Specific File : Ctrl + F

Full Project : Ctrl + Shift + F

(15) Switcher Popup

Open Switcher Popup : Ctrl + Tab

Continue press Ctrl and use ↑/↓/←/→ for move one place to another

(16) Forward Move & Backward Move

Backward : Ctrl + Alt + ← (Left-Arrow)

Forward : Ctrl + Alt + → (Right-Arrow)

(17) Next/previous highlighted error

F2 or (Shift + F2)

(18) Open Java Doc

Select specific method name and press,

Ctrl + Q

(19) Find All commands

Ctrl + Shift + A

(20) Move Line Up/Down

shift + alt + ↑/↓

Thanks...


J
Joa Ebert

The LineMover plug-in works very well and is an acceptable solution.


Very simple, I use this all the time; it binds to Control-Shift-Up Control-Shift-Down
There is no need for this plugin as mentioned elsewhere Alt+Shift+Up and down perform this action.
P
PanCrit

You can move several lines together with move statement. Are you trying to move partial lines? I don't think there's a way in Idea.


As I said in the question, move statement is not what I need but an equivalent to Eclipse's move line. I also found the LineMover plug-in for IDEA. Maybe that will work.
S
SHAKU

try command+shift+up/down this will auto adjust the indentation