Write and edit source code | IntelliJ IDEA (original) (raw)

When you work with code, IntelliJ IDEA ensures that your work is stress-free. It offers various shortcuts and features to help you add, select, copy, move, edit, fold, find occurrences, and save code.

For navigation inside the editor, refer to Editor basics.

Transpose characters

  1. In the editor, place the caret at the characters you want to swap.
  2. Go to .
    There is no default shortcut for this action. You can assign a custom shortcut.

The floating toolbar contains various actions for code editing. It appears when you select a code fragment in Java, Kotlin, JSON, XML, YAML, and SQL files in the editor.

Floating toolbar for code editing

Enable the toolbar

  1. Press Ctrl+Alt+S to open settings and then select .
  2. In the Editor section, disable the Hide floating toolbar for code selection option.
  3. Apply the changes and close the dialog.

Customize the toolbar

  1. Press Ctrl+Alt+S to open settings and then select .
    Alternatively, click More on the toolbar and select Customize Toolbar.
  2. Add or remove actions under Floating Code Toolbar.
    For more information, refer to Menus and toolbars.
  3. Apply the changes and close the dialog.

Lines of code

IntelliJ IDEA offers several useful shortcuts for manipulating code lines.

Copy and paste code

You can use the standard shortcuts to copy Ctrl+C and paste Ctrl+V any selected code fragment. If nothing is selected, IntelliJ IDEA automatically copies as is the whole line where the caret is located.

By default, when you paste anything in the editor, IntelliJ IDEA performs "smart" paste, for example, pasting multiple lines in comments will automatically add the appropriate markers to the lines you are pasting. If you need to paste just plain text, press Ctrl+Alt+Shift+V.

Code selection

Select code constructs

Select code according to capitalization

  1. In the Settings dialog (Ctrl+Alt+S) , go to .
  2. Select the Use "CamelHumps" words checkbox.

If you want to select words with a double click according to capitalization, make sure that the Honor "CamelHumps" words settings when selecting on double click checkbox right below is also selected.

Code statements

Move statements

Complete current statement

Unwrap or remove statement

  1. Place the caret at the expression you want to remove or unwrap.
  2. Press Ctrl+Shift+Delete or select Code | Unwrap/Remove from the main menu.
    IntelliJ IDEA shows a popup with all actions available in the current context. To make it easier to distinguish between statements to be extracted and statements to be removed, IntelliJ IDEA uses different background colors.
    Select a statement to unwrap
  3. Select an action and press Enter.
    Unwrapping result

Code fragments

Code folding

IntelliJ IDEA automatically recognizes certain code structures and makes them foldable. You can also define custom folding regions.

Folded code fragments are shown as shaded ellipses (Folded fragment). If a folded code fragment has errors, IntelliJ IDEA highlights the fragment in red.

By default, folding icons in the gutter show up on hover. You can change this and configure other code folding settings in .

Go to in the main menu (Ctrl+Shift+A) and search for folding. IntelliJ IDEA will show a popup with all folding actions with their shortcuts:

Expand or collapse code elements

Fold or unfold nested fragments

Custom folding regions

You can make any code fragment foldable by marking it as a custom folding region with dedicated comments. After that, you can expand and collapse the fragment with Ctrl+. or have it collapsed automatically on opening the file.

  1. In the editor, select a code fragment and press Ctrl+Alt+T.
  2. From the popup menu, select <editor-fold...> Comments or region...endregion Comments.
  3. Optionally, specify a description under which the collapsed fragment will be hidden.
  4. To collapse or expand the created region, press Ctrl+..
  5. To navigate to the created custom region, press Ctrl+Alt+..

Configure code folding icons

You can select how to display folding icons that appear in the gutter or disable them completely.

  1. Press Ctrl+Alt+S to open settings and then select .
  2. From the Show code folding arrows list, select Always or On mouse hover.
    Clear the checkbox to disable the icons.

Last modified: 01 April 2025