What’s Mining: Multiple Cursors and Selection

Posted on by Tatiana Vasilyeva

Hello everyone,

If you, as me, often dream of being in several places at once you will like this new feature coming to RubyMine from IntelliJ platform side! Please welcome multiple cursors and selection that you can already try in the last EAP version:

multiple_cursors

It was the top voted editor feature in our tracker and we hope you will like it. Let me go through this short demo in more detail and show you all the tricks.

Set multiple cursors

Let’s start with the very beginning. Using Alt with the mouse click you can set the cursors in all places you need (please note that you may always change the shortcut in Settings -> Keymap -> Editor Actions -> Add or Remove Caret):

multiple_cursors_1

multiple_cursors_2

You can also use keyboard. Please go to Settings -> Keymap -> Editor Actions and set up the shortcuts for Clone Caret Above and Clone Caret Below actions:

multiple_cursors_3

multiple_cursors_4

To switch off the multiple cursors and get back to single one, please press ⎋/Escape.

Edit your code simultaneously

Now, when multiple cursors are set, you can make some changes. For example, select the first words with Move Caret to Next Word with Selection (⌥⇧→/Ctrl+Shift+Right) action and move them to the end of lines with Cut (⌘X/Ctrl+X), Move Caret to Line End (⌘→/End) and Paste (⌘V/Ctrl+V) actions:

multiple_cursors_5

multiple_cursors_6

Or you can go back to the beginning of lines with Move Caret to Line Start (⌘←/Home) and capitalise the first letters with Right with Selection (⇧→/Shift+Right) and Toggle Case (⌘⇧U/Ctrl+Shift+U) actions:

multiple_cursors_7

multiple_cursors_8

Use code completion in multiple places at once

We’ve added an opportunity to use autocompletion and live templates with multiple selection as well. The context is determined from primary cursor’s location, resulting changes are applied to all cursors:

multiple_cursors_9

multiple_cursors_10

Find code occurrences to change

You can also easily change any repeating code fragment with Select All Occurrences (⌃⌘G/Ctrl+Shift+Alt+J) and Select/Unselect Next Occurrence (⌃G and ⇧⌃G/Alt+J and Shift+Alt+J ) actions:

multiple_cursors_11

multiple_cursors_12


Multiple cursors and selection feature as cool as it is to use now, it still has a long way to go: its implementation remains to be refined, and some limitations need to be dealt with. So we would really appreciate your feedback about it. Share your thoughts in our discussion forum and submit bug reports to the issue tracker. Thanks!


Develop with pleasure!
JetBrains RubyMine Team

Comments below can no longer be edited.

29 Responses to What’s Mining: Multiple Cursors and Selection

  1. Fabio Scognamiglio says:

    March 19, 2014

    awesome!

    but i’m curious to know what will happen with vim plugin enabled
    😀

    who knows?!

  2. RubyMineでマルチカーソル/選択 | JetBrains ブログ says:

    March 20, 2014

    […] 原文 […]

  3. RubyMine Hinoki Goes Beta! | JetBrains RubyMine Blog says:

    March 20, 2014

    […] ← What’s Mining: Multiple Cursors and Selection […]

  4. Ron Elliott says:

    June 8, 2014

    I have been waiting for this feature for a while. Sadly it’s still not enough for me to move back from sublime text. The VERY simple key combos used it ST still make it king of this feature. Jetbrains needs to deemphasize the mouse and long key combos.

    • Shubham Waghe says:

      August 17, 2018

      Absolutely agree! Nothing beats Sublime’s Ctrl+D, Ctrl+K shortcut.

  5. Georg says:

    June 17, 2014

    Activating this dangerous feature by default was a completely stupid idea!

    • Tatiana Vasilyeva says:

      June 18, 2014

      What is wrong with the feature?

      • Matti Airas says:

        June 23, 2014

        It’s lovely already as it is – the feature I missed the most when I switched from ST to PyCharm. In a way I agree with Georg, however. Multiple cursors is a feature that needs to be learned – it’s not discoverable at all. Since the feature is a very advanced one, I’m not sure if you can do much about it. Maybe pop-up a non-modal dialog when it’s enabled for the first time?

        If you stumble upon it without knowing, I’m sure it’s easy to wreak a lot of havoc with it, so maybe it could be disabled by default. I think you could argue for either.

        • sean says:

          September 7, 2014

          Ctrl+Z … don’t be so dramatic.

          • Ejder Yurdakul says:

            July 1, 2015

            Gees, i cant disable this feature. It cuts my code like a samurai sword.

            • Tatiana Vasilyeva says:

              July 1, 2015

              You can change or even delete a shortcut I guess.

    • olol says:

      December 14, 2018

      You mean, in an environment where you’re supposed to use a VCS and commit often, using an editor that provides

      – autosave
      – ctrl + z
      – local history

      ????

  6. allbutone says:

    November 6, 2014

    In Sublime, I can select multiple lines and press “Ctrl + Shift + L” to split into lines, then edit them with “multiple select” fluently, but in IDEA, I can’t find the same feature. will this feature be added ?

    • Alexander Zolotov says:

      November 6, 2014

      It seems that RubyMine doesn’t have this feature. Feel free to file a feature request at http://youtrack.jetbrains.com

  7. allbutone says:

    November 6, 2014

    I know I can set shortcut for “unselect occurrence”, but I can’t skip this occurrence and select the occurrence next to it, In Sublime, I can simply press “Ctrl + K, D” to achieve that, will this feature be fixed ?

    • Alexander Zolotov says:

      November 6, 2014

      There is an action ‘Find Next / Move to Next Occurrence’ for that.

  8. WebStorm: IDE for Javascript | datajs says:

    May 28, 2015

    […] What’s Mining: Multiple Cursors and Selection […]

  9. Michael K. says:

    October 23, 2015

    Saw this in the new Tips and Tricks video just uploaded by jetbrains. I already used the syncedit plugin for a longer time and missed this feature for some time that the syncedit stopped working in IntelliJ very much. It’s good that the multiple cursor works in a similar way but it does not fully replace syncedit. I know that the plugins (there was a version 2 from a different author) are very old and not updated since years but the functionality is very good and unique and could maybe move into IntelliJ in this context.

    • Tatiana Vasilyeva says:

      October 23, 2015

      What is the most desired feature that syncedit has and RubyMine has not for you?

  10. Python:Is there multiple cursor-like functionality in PyCharm? – IT Sprite says:

    November 4, 2015

    […] Link to a blog post on usage for anyone interested: blog.jetbrains.com/ruby/2014/03/… […]

  11. Ben Creasy says:

    February 24, 2016

    The Sublime trick of multiple cursors over a selection with CMD+SHIFT+L is requested at https://youtrack.jetbrains.com/issue/IDEA-122181 so you can vote for it if you want it.

    • Boris says:

      July 13, 2016

      what about aligning multiple carets vertically with a shortcut?

      in order to go from here
      a |: 1,
      aaaa |: 2,
      aa |:3,
      aaaaaa |:4,

      to here:
      {
      a |: 1
      aaaa |: 2
      aa |: 3
      aaaaaa|: 4
      }

  12. Boris says:

    July 13, 2016

    is there a way aligning the multi cursor in one vertical line like in sublime?

    https://github.com/shagabutdinov/sublime-align-cursors

    • Tatiana Vasilyeva says:

      July 13, 2016

      Could you please take a look at this issue. Is it the right one? If so, please watch/vote for it to get any news and updates on the topic.

  13. Umer farooq Mughal says:

    December 16, 2017

    Is there a way to increment numbers when using multiple cursors?
    Like
    abc_|1
    xyz_|1
    expected:
    abc_1
    xyz_2

  14. David says:

    February 11, 2020

    Hi,

    How do you move the multi-caret over logical elements
    blah(“|One Word”, blah.toString());
    blah(“|Two Words Here”, blah);
    blah(“|Three Words are here”, blah);

    I can’t get the carets over the complete strings in quotes going from start position.
    Also can’t work back from end of line because of blah.toString() vs blah

    • Olga Kuvardina says:

      February 18, 2020

      Hello David,
      have you tried using Move Caret to Next Word shortcut?

Subscribe

Subscribe for updates