Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select all instances of a variable and edit variable name in Sublime

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:

enter image description here

Is there a keyboard shortcut that will let me select all of those instances of the variable and edit them all at once?


Things I've Tried:

D, K, and U lets me select them one-by-one, but I have to manually exclude the non-variable string matches:

enter image description here

And using CtrlG simply selects all the string matches:

enter image description here

Clearly, Sublime is able to differentiate between variable and string matches. Is there no way to select just the variable matches?

like image 858
Oskar Persson Avatar asked May 30 '13 19:05

Oskar Persson


People also ask

How do I change all occurrences of a variable name in R?

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.

How do you change all variables in Python?

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.

How do you replace words in Sublime Text?

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.

How do I select and comment in Sublime Text?

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 + / .


2 Answers

  1. Put the cursor in the variable.

    Note: the key is to start with an empty selection. Don't highlight; just put your cursor there.

text cursor on variable

  1. Press D as needed. Not on a Mac? Use CtrlD.

more instances of variable highlighted

Didn't work? Try again, making sure to start with nothing selected.

More commands:

Find All: CtrlG selects all occurences at once. Not on a Mac? AltF3

Undo Selection: U steps backwards. Not on a Mac? CtrlU

Quick Skip Next: KD skips the next occurence. Not on a Mac? CtrlKCtrlD

Sublime Docs

like image 191
Nolan Amy Avatar answered Sep 17 '22 14:09

Nolan Amy


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.

like image 20
elaRosca Avatar answered Sep 19 '22 14:09

elaRosca