Edit code with multiple cursors in PhpStorm
Learn how to use multiple cursors to edit or insert text at several locations simultaneously.
Lesson Content
In PhpStorm, clicking a variable highlights all of its references. This makes it easy to see where a value is used, but editing every occurrence one at a time is unnecessary.
Place the cursor on the variable name and press Ctrl+G on macOS, or Alt+J on Windows or Linux. PhpStorm selects the current occurrence, so you can start typing a replacement:
Ctrl+GThe first occurrence is selected while the other references remain highlighted. Press Ctrl+G again to add the next occurrence to the selection. Continue pressing it until every instance you want to change is selected, then type the new variable name. PhpStorm updates all selected occurrences at the same time.
If you change your mind, press Ctrl+Z on Windows or Linux, or Cmd+Z on macOS, to undo the edit:
Ctrl+ZMultiple cursors are also useful when you need to insert text at specific positions rather than replace an entire variable. For example, to add a prefix to several table names, click exactly where the prefix should begin in the first name. Hold Alt and click each additional location on Windows or Linux, or hold Option and click on macOS.
Each click adds another cursor. Start typing the prefix, and PhpStorm inserts it at every cursor position simultaneously:
Alt+ClickOn macOS, use:
Option+ClickThis lets you make precise changes across several unrelated locations without selecting the surrounding text.
Join the discussion!
Comments
Want to comment on this lesson?
Log in to leave comments.