Search code examples
phpstorm

Multiple cursors in PhpStorm like Sublime Text 3?


You can use Alt + Click to set multiple cursors in PhpStorm but if you want to quickly make an array of some list like this, it's simply too many lines to click: (example from Sublime Text 3)

enter image description here

In Sublime Text 3 you simply select all the lines and hit Ctrl + Shift + L and it will set cursors at the end of each line and then you can hit Home button to set the cursors at the beginning or whatever.

I can't find anything in docs... maybe someone knows how to do this in PHPStorm or at least how to make some keyboard shortcut with macro or something?


Solution

  • Such action is available from 2020.2 version -- see IDEA-122181.

    It's called Add Caret Per Selected Line and by default has Alt + Shift + G shortcut on Windows (⌥⇧G on Mac).


    There is also Extra Actions plugin: it claims to do that and a few other things.


    Current alternatives (that are much easier than the mentioned Alt + Click):

    1. Just go into Column Selection Mode (from the "Edit" menu, Alt + Shift + Insert on Windows, Cmd + Shift + 8 on Mac). Exit that mode when done.

    2. Alternatively, to add multiple carets (Clone Caret Below / Above):

      • On Windows: Press Ctrl twice, and then without releasing it, press the Up or Down arrow keys.
      • On Mac: Press Ctrl + Shift + Down / Ctrl + Shift + Up
    3. You can also make a multiple selection by pressing Shift + Alt and dragging the caret.

      From https://www.jetbrains.com/help/phpstorm/working-with-source-code.html#multiple_cursor