Multiple cursors and selection ranges | IntelliJ IDEA (2024)

When typing, copying, or pasting in IntelliJIDEA editor, you can toggle multiple cursors so that your actions apply in several places simultaneously. Advanced editor actions, such as code completion and live templates are supported as well and will apply to each caret.

The number of carets that you can add in a file is limited to 1000. If you want to increase that limit, open the custom JVM options Help | Edit Custom VM Options and add the following line: -Deditor.max.caret.count=<NEW_LIMIT>.

The most recently added caret is considered primary. Highlighting of the current editor line, completion lists, and other visual assistance features will apply to the primary caret. This caret will also remain when you turn off multiple carets.

Add and remove carets

There are two options of where on the code line the carets can be added:

To existing characters

Using virtual spaces

If there is no character, tab, or whitespace at the position where you want to add a new caret, the new caret will be added to the last character position in the target line.

This way you can add new carets anywhere after the last character in any line. As soon as you start typing at a position beyond the end of the line, the necessary number of spaces will be added between the end of the line and the beginning of your input.

You can enable virtual spaces by selecting the Allow placement of caret after end of line checkbox on the Editor | General page of settings Ctrl+Alt+S. Alternatively, virtual spaces are also enabled in the column selection mode.

Add or remove carets at selected locations using mouse

  • Alt+Shift+Click at the target location to add another caret.

    Multiple cursors and selection ranges | IntelliJIDEA (1)
  • Alt+Shift+Click at one of the multiple carets to remove it. The last caret will not be removed.

Add carets above or below the current caret using keyboard

  • Press Ctrl twice, and then without releasing it, press up or down arrow keys.

    If virtual spaces are enabled, new carets will be added exactly above or below the current caret position. Otherwise, in lines, which are shorter than the current offset, carets will be added at line ends.

    Multiple cursors and selection ranges | IntelliJIDEA (2)
  • Enable the column selection mode (press Alt+Shift+Insert) and then press Shift+Up/Shift+Down.

  • Press Ctrl+Shift+A, type Clone caret, and choose the desired action from the suggestion list:

    Multiple cursors and selection ranges | IntelliJIDEA (3)

    Note that by default, these actions are not associated with keyboard shortcuts. You can assign your custom shortcuts to these actions as described in configuring keyboard shortcuts.

Add carets at each line of the current document

Add carets to the end of each line in the selected block

  • Select a code block in the editor and then press Alt+Shift+G or go to Edit | Add Carets to Ends of Selected Lines in the main menu.

Remove multiple carets

  • Press Esc to delete all existing carets, except the one that was added last.

  • Alt+Shift+Click at one of the multiple carets to remove it. The last caret will not be removed.

Select multiple non-contiguous ranges

When you select multiple text ranges (non-contiguous selection), note the following:

  • Each selection range is associated with its own caret, so you can start typing to replace all selected ranges with your input, or you can press Left Arrow or Right Arrow to remove the selection ranges but keep multiple carets at beginnings/ends of the ranges.

  • As soon as selection ranges overlap, they are merged into a single selection range with a single caret.

  • Selection works independently of the code structure. That is, selection ranges can include any characters, identifiers, words in string literals, comments, or their parts. So you have to be careful when changing the selected ranges as they may include different identifiers or their parts.

Select multiple words or text ranges

  • While Alt+Shift+Click will add a new caret, double-clicking words or dragging the mouse over text ranges (keeping the same keys pressed) will add new carets with the corresponding selections.

    Multiple cursors and selection ranges | IntelliJIDEA (4)

Select multiple occurrences of a word or a text range

  1. If you want to select words, place the caret at an occurrence of the desired word. Otherwise, select the desired range with the mouse or with keyboard shortcuts.

  2. Do one of the following:

    • Successively press Alt+J to find and select the next occurrence of case-sensitively matching word or text range.

      Multiple cursors and selection ranges | IntelliJIDEA (5)
    • Press Ctrl+Alt+Shift+J to select all case-sensitively matching words or text ranges in the document.

  3. To remove selection from the last selected occurrence, press Alt+Shift+J.

  4. After the second or any consecutive selection was added with Alt+J, you can skip it and select the next occurrence with F3. To return the selection to the lastly skipped occurrence, press Shift+F3.

    Multiple cursors and selection ranges | IntelliJIDEA (6)

Find and select multiple occurrences of a string

  1. Press Ctrl+F or choose Edit | Find | Find from the main menu. The search pane appears at the top of the active editor.

  2. Enter the string that you want to find and select. To the right of the search string, you will see the number of occurrences in the current document.

  3. Optionally, restrict your search by case Multiple cursors and selection ranges | IntelliJIDEA (7) Alt+C or to match only whole words Multiple cursors and selection ranges | IntelliJIDEA (8) Alt+W.

  4. Press Ctrl+Alt+Shift+J or click Select All Occurrences Multiple cursors and selection ranges | IntelliJIDEA (9) on the toolbar.

Use mouse to select rectangular fragments of text in normal selection mode

  1. Make sure that the column selection mode is disabled.

  2. To select ranges as a single rectangle, do one of the following:

    • Place the caret at one corner of the rectangle, and then Alt+Shift+Middle-Click at the diagonally opposite corner.

    • Alt+Click and drag the mouse to make the selection.

  3. To select ranges as multiple rectangular selections, Ctrl+Alt+Shift+Click and drag the mouse over the desired parts of code.

  4. As a result, you will have multiple selection ranges in each affected document line. On lines that are shorter than the rectangle, the selection will only span to the last character.

    Multiple cursors and selection ranges | IntelliJIDEA (10)

Column selection mode

Toggle between normal and column selection modes

  • Press Alt+Shift+Insert.

  • In the main menu, go to Edit | Column Selection Mode.

  • From the context menu of the editor, choose Column Selection Mode.

In the column selection mode, keyboard navigation and selection shortcuts in the current document work differently to simplify adding multiple carets and making rectangular selections:

  • You will be able to place the caret anywhere after the last character in any line. As soon as you start typing at a position beyond the end of the line, the necessary number of spaces will be added between the end of the line and the beginning of your input.

  • Pressing Shift+Up/Shift+Down or dragging the mouse up and down will add new carets above/below the current one instead of making a continuous selection.

    Multiple cursors and selection ranges | IntelliJIDEA (11)
  • The enabled column selection mode only affects the current editor tab. If you close or reopen the tab, it will switch back to the normal mode.

If the column selection mode is enabled for the current document, the Column indicator is displayed on the status bar.

Copy and paste with multiple carets

When text ranges selected with multiple carets are copied Ctrl+C or cut Ctrl+X, selections for each caret are placed to the clipboard as separate lines, even if the original selections were on the same line.

If the column selection mode was enabled, the selection could also include empty spaces after ends of lines. These will be replaced with whitespaces in the clipboard if you copy the selection.

When you paste any multi-line content from the clipboard, you can add multiple carets for each line in desired places, and then press Ctrl+V to paste each line at its own caret.

Last modified: 26 May 2024

Sticky linesLightEdit mode

Multiple cursors and selection ranges | IntelliJ IDEA (2024)

References

Top Articles
2024 March Madness predictions: NCAA bracket expert picks against the spread, odds in Thursday's Round 1 games
'This has to be the best year yet': Johnson embracing critical role ahead of 2024 season
NOAA: National Oceanic &amp; Atmospheric Administration hiring NOAA Commissioned Officer: Inter-Service Transfer in Spokane Valley, WA | LinkedIn
Joe Taylor, K1JT – “WSJT-X FT8 and Beyond”
Danatar Gym
Top Financial Advisors in the U.S.
Cumberland Maryland Craigslist
O'reilly's In Monroe Georgia
Xrarse
Tabler Oklahoma
Youtube Combe
Epaper Pudari
Days Until Oct 8
Sulfur - Element information, properties and uses
The Blind Showtimes Near Amc Merchants Crossing 16
Sussyclassroom
Scream Queens Parents Guide
Coomeet Premium Mod Apk For Pc
Mini Handy 2024: Die besten Mini Smartphones | Purdroid.de
Kentuky Fried Chicken Near Me
Hellraiser 3 Parents Guide
Pawn Shop Moline Il
Tuw Academic Calendar
Harbor Freight Tax Exempt Portal
John Philip Sousa Foundation
Worthington Industries Red Jacket
Core Relief Texas
The Posturepedic Difference | Sealy New Zealand
Kamzz Llc
Productos para el Cuidado del Cabello Después de un Alisado: Tips y Consejos
"Pure Onyx" by xxoom from Patreon | Kemono
Baldur's Gate 3 Dislocated Shoulder
2015 Chevrolet Silverado 1500 for sale - Houston, TX - craigslist
Exploring TrippleThePotatoes: A Popular Game - Unblocked Hub
Ark Unlock All Skins Command
The Best Carry-On Suitcases 2024, Tested and Reviewed by Travel Editors | SmarterTravel
42 Manufacturing jobs in Grayling
Main Street Station Coshocton Menu
Chatropolis Call Me
Anya Banerjee Feet
How To Upgrade Stamina In Blox Fruits
888-822-3743
5A Division 1 Playoff Bracket
Mychart Mercy Health Paducah
Best Haircut Shop Near Me
Wolf Of Wallstreet 123 Movies
House For Sale On Trulia
Ty Glass Sentenced
Walmart Front Door Wreaths
Jigidi Jigsaw Puzzles Free
Morgan State University Receives $20.9 Million NIH/NIMHD Grant to Expand Groundbreaking Research on Urban Health Disparities
Palmyra Authentic Mediterranean Cuisine مطعم أبو سمرة
Latest Posts
Article information

Author: Msgr. Refugio Daniel

Last Updated:

Views: 6478

Rating: 4.3 / 5 (74 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Msgr. Refugio Daniel

Birthday: 1999-09-15

Address: 8416 Beatty Center, Derekfort, VA 72092-0500

Phone: +6838967160603

Job: Mining Executive

Hobby: Woodworking, Knitting, Fishing, Coffee roasting, Kayaking, Horseback riding, Kite flying

Introduction: My name is Msgr. Refugio Daniel, I am a fine, precious, encouraging, calm, glamorous, vivacious, friendly person who loves writing and wants to share my knowledge and understanding with you.