Adding, Deleting and Moving Code Elements
On this page:
- Adding lines
- Duplicating lines
- Deleting lines
- Moving lines
- Moving statements
- Moving code element left or right
To add a line
To duplicate a line or fragment
- Place the caret at the line to be duplicated, or select the desired fragment of text.
- Press Ctrl+D.
To remove a line
- Press Ctrl+Y to delete the line at caret.
To move a line
To move a statement up or down
- Select a statement to be moved, or just place the caret at the first or last lines of a multi-line statement. Note that if moving a statement is not allowed in the current context, the commands will be disabled.
- Do one of the following:
If you apply the same commands to a line at caret, or a to a selection, it will be moved one line up or down.
IntelliJ IDEA moves the selected statement above the previous one, or directly underneath the next one, performing the syntax check. For example, place the caret at the method declaration:
After moving the statement:
To move code element to the left or to the right
- Place the caret at the desired code element, or select the elements to be moved.
- Do one of the following:
Examples of code elements for which this functionality is currently implemented:
See Also
```
Reference:
Last modified: 21 March 2017