If I select a variable (not just any string) in my code, all other instances of that variable get a stroke (white outline) around them:
Is there a keyboard shortcut that will let me select all of those instances of the variable and edit them all at once?
⌘D, ⌘K, and ⌘U lets me select them one-by-one, but I have to manually exclude the non-variable string matches:
And using Ctrl⌘G simply selects all the string matches:
Clearly, Sublime is able to differentiate between variable and string matches. Is there no way to select just the variable matches?
It is achieved by selecting the function or variable we want to change and pressing Ctrl + Shift + Alt + M. It will select all occurrences in scope, you will have to just type a new name.
If you're using the Python Idle(GUI) you can Ctrl + H and select Replace All. Show activity on this post. Visual Studio Code is Ctrl + Shift + L and begin typing. Sublime/Atom are alt + F3.
Or, if you want to find and replace text in a number of files at once, press Command + Shift + F or Control + Shift + H to open Sublime Text's Find in Files tool that can search and replace across as many files as you have open or select from its menu.
To add single-line comments, put the text cursor on the line to comment-out or highlight multiple lines and type CMD + / on Mac, for Linux and Windows use CTRL + / .
Put the cursor in the variable.
Note: the key is to start with an empty selection. Don't highlight; just put your cursor there.
Didn't work? Try again, making sure to start with nothing selected.
More commands:
Find All: Ctrl⌘G selects all occurences at once. Not on a Mac? AltF3
Undo Selection: ⌘U steps backwards. Not on a Mac? CtrlU
Quick Skip Next: ⌘K⌘D skips the next occurence. Not on a Mac? CtrlKCtrlD
Sublime Docs
I know the question is about Macs, but I got here searching the answer for Ubuntu, so I guess my answer could be useful to someone.
Easy way to do it: AltF3.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With