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.

43 Responses to Working with Multiple Selection in PhpStorm 8 EAP

  1. Nick K says:

    Yeeeeeeeeeeeeheeeeeeeeeeeesssssssssss!!!!!!!!!

  2. Mjolnir says:

    Squee!

  3. Fabio says:

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

  4. Mike says:

    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 says:

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

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

  6. Alexandre says:

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

  7. Fabio says:

    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 says:

      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 says:

      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 says:

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

  8. Kiean says:

    Are there plans to put this into IntelliJ?

    • Maarten Balliauw says:

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

      • JP Veilleux says:

        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 says:

          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.

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

  10. aomm says:

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

  11. Fabio says:

    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.

  12. Multiple selection works on Linux?

  13. Florian says:

    Yeehaw, what a feature.

    It’s like Harry Potter’s Patronus spell.

  14. jerry says:

    how do I skip a word ?

  15. Nate Wiebe says:

    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?

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

  17. Randy says:

    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 says:

      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 says:

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

  18. AllTheCode says:

    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.

  19. SublimeConvert says:

    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?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">