IntelliJ IDEA 2021.1 Help

Multiple carets and selections

When you type, edit, copy, or paste code, you can use multiple carets to perform these actions simultaneously on different lines. For example, you can add comment markers to multiple lines, or remove some characters in several occurrences of a word.

Add multiple carets

There are several ways in which you can add multiple carets:

  • Press and hold Shift+Alt and click at the next caret location.

    Add multiple carets

  • You can press Ctrl twice and then, without releasing it, press the Up or Down arrow keys.

    Add multiple carets

  • Press Shift+Alt and drag the caret to also select multiple words or text ranges.

    select text ranges

Move carets

After you set multiple carets, you can use the Alt+↑/↓ shortcut to move them back and forth. By default, the caret is moved to the end of the current word. However, you can change the caret's behavior.

Configure the caret behavior

  1. In the Settings/Preferences dialog Ctrl+Alt+S, go to Editor| General.

  2. In the Caret Movement section, select an appropriate behavior from the list.
    the Caret Movement settings

    For more information on the available settings options, refer to the General Settings.

Remove multiple carets

You can remove all of the carets with one action or one caret at a time.

  • Press Escape to delete all added carets.

  • Press Shift+Alt and click carets that you want to remove.

Enable the column selection mode

You can make a multiple selection of code in columns enabling a column selection mode. This mode is helpful when you want to edit several lines of code simultaneously.

  1. In the editor, press Alt+Shift+Insert to enable the column selection mode. Alternatively, right-click anywhere in the editor to open the context menu and select Column Selection Mode.
  2. Place the caret at a symbol you need and either drag it up or down, or select a block of code and press the specified shortcut to achieve the same result.

    enable column selection mode

Multi selection in occurrences of code

You can quickly locate all occurrences of the selected element in a file, make a multiple selection, or select the next or the previous occurrences.

Make a multiple selection of occurrences

  • Place the caret at the needed element, then press Alt+J. Press the same key to find the next occurrence.

    Alternatively, keeping Shift+Alt pressed, double-click or drag over the text you want to add to the selection.

    Select occurrences
  • Press Ctrl+Alt+Shift+J to select all occurrences in the file,.

Move the caret to the next or the previous occurrence

  • Press F3 to move the caret to the next occurrence.

    When you press F3, IntelliJ IDEA automatically removes the selection of the current occurrence and selects the next one.

    Move to the next occurrence
  • Press Shift+F3 to move the caret to the previous occurrence.

    IntelliJ IDEA selects all the previous occurrences.

  • To find the next or the previous occurrence of the selected identifier, press Alt+Wheel up or Alt+Wheel down.

Last modified: 08 March 2021