Video Lesson: Edit code with multiple cursors in PhpStorm

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+G

The 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+Z

Multiple 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+Click

On macOS, use:

Option+Click

This lets you make precise changes across several unrelated locations without selecting the surrounding text.

Maggie

Hey, I'm Maggie! 👋

Ask me anything.

Want to chat with Maggie?

Log in for AI tutor access.

Comments

Join the discussion!

Notes

Keep track of what you learn!