Working with Multiple Selection in PhpStorm 8 EAP

Multiple CursorsEarlier this week, we released the PhpStorm 8 EAP with a number of new features and improvements. We hear what you say on Twitter and on our issue tracker and that’s why we’re including your number one request: Multiple Selection. Let’s see how we can work with them!

Multiple Selection

With Multiple Selection, we can work with multiple cursors in one file simultaneously. Let’s start with some basics: press and hold Alt and use the mouse to select the locations where a cursor is desired.

Please note that default hotkey for multiple selection (multiple carets) add/remove caret has been changed from PhpStorm 8 EAP 138.256 build to Alt+Click (used to be Alt+Shift+Click before). It can be always changed in Settings | Keymap | Add or Remove Caret.

Cursor locations can also be added using Select Next Occurrence (Alt+J on Windows, Ctrl-G on Mac OS X): we can add the next occurrence of the current word to the selection and start working from there. Also we can Unselect Occurrence (Alt+Shift+J on Windows, Ctrl-Shift-G on Mac OS X). Select All Occurrences (Ctrl-Cmd-G on Mac OS X is already available, Windows hotkey Ctrl+Alt+Shift+J will be available from the next EAP - use double shift | Select All Occurrences action for now) will select all occurrences of current word/symbol in multiple caret mode. Hitting Escape lets us work with one cursor again.

Here’s a video of these concepts in action in an HTML file.

Multiple selection works with all languages supported by PhpStorm such as PHP, HTML, JavaScript, CSS and more. Here’s a (slightly insane) example of converting a Markdown file into PHP code using nothing but multiple selection:

Autocompletion (Ctrl+Space) and live templates are also available with multiple selection. Copy/paste also works: copying will store selected text from all cursors on the clipboard, pasting will add all clipboard text to every cursor location.

Here’s another video where we demonstrate Column Selection Mode (Alt and drag the mouse to select a region of text) as well as Emmet support inside multiple selection:

Refactoring

While we agree multiple selection is super awesome, there are situations where refactorings are more appropriate. With great power comes great responsibility so it’s worth knowing when to use that power! Consider the following piece of code:

Rename refactoring

How can we rename the $config variable to $configuration here? It’s really tempting to use multiple selection but that would break all usages of the $config variable. It’s better to use a Rename refacoring in this case (Shift+F6).

Another example would be replacing strings in one document: using Select Next Occurrence (Alt+J on Windows, Ctrl-G on Mac OS X) we can easily select these strings and update them. But having the same string multiple times in a document is an antipattern… Instead, try using the Extract Variable in such case.

Want to give it a try? Find a new exercise in our PhpStorm Hands-On Workshop Materials!

As we are still working on this feature, we welcome your feedback through our issue tracker, in the comments below or in our forums! Current issues can be found by this link.

Develop with pleasure!
– JetBrains PhpStorm Team

This entry was posted in Cool Feature, Early Access Program and tagged , , , , , , , . Bookmark the permalink.
  • Nick K

    Yeeeeeeeeeeeeheeeeeeeeeeeesssssssssss!!!!!!!!!

  • Mjolnir

    Squee!

  • Fabio

    Delete key doesn’t work to delete CRLF and join multiple lines. I had to use backspace instead.

  • Mike

    And if ALT+SHIFT+MIDDLE_CLICK does nothing, where in the keyboard shortcuts can I look it up?
    Because I can not search for this combination there as the search field loses focus due to the click.

    • Mikhail Vink

      Multiple Selection hotkeys are not yet configurable, but soon it’ll be possible in Settings | Keymap.

  • Pingback: PHPStorm 8 (early access version) released - for free - Dev Metal

  • Alexandre

    hi, great feature!
    is there an ETA for version 8 release?

    • Mikhail Vink

      No strict ETA right now, but around May

  • Fabio

    The shortcut alt+shift is not well chosen as it is the default shortcut to switch between keyboards under Windows. As my default keyboard is not US, my keyboard is changed everytime I press Alt+Shift.

    I can disable Windows shortcut but it is not very simple and some people may need to use the original shortcut.

    Can’t you use “Alt+click” (or better “Ctrl+click”) instead of alt+shift+click to add other locations?
    It would be easier to press and Ctrl+click is the shortcut used by any other software (Word, Excel, drawing software, Sublime Text etc.).
    I wouldn’t mind personaly if ctrl+click was used for multiple selection instead of “Navigate>declaration”.

    • Andriy Bazanov

      ATM shortcut is not configurable, at all (you cannot change it via Keymap). When it became possible to change — you can then assign another shortcut to whatever you want / what suits you best. But no one will change default Ctrl+Click (in Default keymap) to something else — it has been used for “Navigate | Declaration” for years (for PhpStorm it is since very first version).

    • Mikhail Vink

      Configuration of hotkey in Settings | Keymap will be possible in the nearest future, so you’ll be able to change it to any other combination.

      However, as Andriy already mentioned in the previous comment, changing default hotkey for multiple selection to Ctrl+Click is not an option in any case from JetBrains side – it stands for Navigate | Declaration and will stay so.

      • Fabio

        Thanks. As long as it is possible to change it for “Alt+Click” or any other simpler combination, I think everyone will be pleased.

  • Kiean

    Are there plans to put this into IntelliJ?

    • Maarten Balliauw

      I would expect it to show up in IntelliJ IDEA in one of the future releases.

      • JP Veilleux

        Isn’t supposed to be the other way around with IntelliJ IDEA based sub-products?

        I’m sure I’m missing something here but I thought that features trickled down from IntelliJ to the more focused editions ie: WebStorm, RubyMine, PHPStorm etc.

        • Mikhail Vink

          That really depends on release cycles and individual priorities of products, so current case of having multiple selection in WebStorm/PhpStorm IDEs first is absolutely valid case.

  • http://xatzis.com George Hadjivarnava

    Alt +drag to select a rectangle of text is the best thing. Very easy to replace text in lists and move things around!

  • aomm

    what’s the name of this plugin on the right of the IDE on video?
    like sublime’s super preview。
    how to enable it?

  • Fabio

    Hi,

    Do you intend to implement the ability to insert sequences like the text-pastry plugin for sublime text?
    It is a very useful complement to multicursors. For the moment, I’m using Emmet to emulate this behavior.

  • http://nevergone.hu/ The NeverGone

    Multiple selection works on Linux?

  • Florian

    Yeehaw, what a feature.

    It’s like Harry Potter’s Patronus spell.

  • jerry

    how do I skip a word ?

    • Mikhail Vink

      Do you mean skipping occurrence?

      • jerry

        year!

    • Mark

      Yes, How do you skip an occurrence?
      In SublimeText is cmd (d + k)

  • Nate Wiebe

    When escaping multiple carets, it would be nice to be able to return to the first instance, not the last selected. Could this be an option?

    • Mikhail Vink

      Now it should work in this way – please try latest EAP.

  • http://flowcom.se Tim Samuelsson

    This was the only thing i missed from sublime text. I love using an IDE!!

  • http://supremetechs.com Randy

    When I’m using Sublime I frequently add multiple selections with ctrl + shift + up/down arrow. Is this possible with PHPStorm? I don’t like the Alt + click to set the cursors for the multiple selection. My clicking is sometimes inaccurate by a character and messes up my entire group of selections. I would much rather have this available as a shortcut.

    • Liubov Melnikova

      As it stated in the article:

      Cursor locations can also be added using Select Next Occurrence (Alt+J on Windows, Ctrl-G on Mac OS X): we can add the next occurrence of the current word to the selection and start working from there. Also we can Unselect Occurrence (Alt+Shift+J on Windows, Ctrl-Shift-G on Mac OS X). Select All Occurrences (Ctrl-Cmd-G on Mac OS X is already available, Windows hotkey Ctrl+Alt+Shift+J ) will select all occurrences of current word/symbol in multiple caret mode. Hitting Escape lets us work with one cursor again.

    • James Osterhout

      I second this – using the keyboard to control multiple cursors would be idea.

      • James Osterhout

        This is exactly what I was looking for: Preferences > Keymap then add keyboard shortcuts for Clone Caret Above and Clone Caret Below.

        It’s all explained here: http://youtu.be/JBkGOPR3-nA?t=3m21s

  • AllTheCode

    Will it be possible to have an option to allow multiple selections using dragging?

    In other words, click and drag mouse to select something, then hold alt and click and drag something else, etc. Instead of just clicking, I’d like to highlight multiple items. Currently it just deselects the previous highlight.

    Thank you.

  • SublimeConvert

    In Sublime, I very often used the keyboard to mark columns of subsequent lines – not based on any word occurrences. Is this possible without using the mouse?

    • Liubov Melnikova

      I am sorry, what do you mean by that? Screenshot can be helpful.

  • http://osedea.com Angus

    This doesn’t seem to work with IdeaVim. For example, I’d like to select multiple occurrences of a word while in command mode, and then use Vim keybindings to edit the text at each cursor. Currently, it will only edit the text at the last cursor. Any fixes for this? This works very well in Sublime and is a feature that I use very often!

    Thanks

  • Michael R. Freiermuth

    On Linux (LXDE openbox)

    Deactivate using
    vi .config/openbox/lxde-rc.xml

    search mousbind
    comment out mousebind A-Left Press

    <!– –>
    <!– –>
    <!– –>
    <!– –>

    and reconfigure openbox
    openbox –reconfigure

  • Dan

    Call me an old classic, but I don’t think I want to use this feature. Is there a way to disable it? In working with PHPStorm 8 I keep getting multiple cursors and selections popping up out of nowhere during my usual keystroke patterns and I have to try to get rid of it in a flurry of annoyed ESC’ing and clicking.

    Thanks!

    • Maxim Kolmakov

      Please invoke ”Find Action”, type Registry, find “editor.allow.multiple.carets” and disable it.