I’ve noticed that when I select the name of a variable, all matching variables will have a line drawn around their name (not a highlight, not a box, but a box with rounded edges, matching the caret
color defined for the theme).
If I use the shortcut to Expand Selection to Word
, the same string I have selected for the variable name will also be matched and selected - even if it’s a partial match of another string, or the case doesn’t match.
Is there some way to simply select all the other instances of the selected variable as they are shown with the caret-colored line drawn around them when I select a variable name?
EDIT(SOLVED): Turns out there’s already an answer for this. I just wasn’t using the right words in my search query to find the other thread about it before posting this.
EDIT: Actually, my specific question isn’t exactly answered in this other thread, but I discovered the answer by reading through it.
basically, instead of selecting the name of the variable, place the caret just before the name of the variable. the other post has a reply explaining that you can use cmd /ctrl +d to then select the variable after the carrot, and subsequent presses of the same shortcut will continue to select the next instances of the variable. if there is a selection you want to skip, after it is selected, you can hit cmd /ctrl +k immediately followed by cmd /ctrl +d to skip that selection and select the next instance.
But, to quickly select ALL instances of a variable, with the caret before the variable name, you instead use Quick Find All
(or the shortcut for it, ⌃+⌘+g, i.e. ctrl+cmd+g on macOS, or ⊞(Windows key)+F3 on Windows). This will select the variable after the caret and all other instances of it in your script.
Please note, however, that if the variable name string exactly matches any word that appears otherwise in your script (e.g. in the text of a comment), those words will also be selected along with the instances of the variable name. This is why it’s a good practice to use camelCase, TitleCase, or add underscores between the words used in variable names.