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

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.


  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


Despite much effort, I have not found a built-in or plugin-assisted way to do what you're trying to do. I completely agree that it should be possible, as the program can distinguish foo from buffoon when you first highlight it, but no one seems to know a way of doing it.


However, here are some useful key combos for selecting words in Sublime Text 2:

CtrlG - selects all occurrences of the current word (AltF3 on Windows/Linux)

D - selects the next instance of the current word (CtrlD)

  • K,D - skips the current instance and goes on to select the next one (CtrlK,CtrlD)
  • U - "soft undo", moves back to the previous selection (CtrlU)

E, H - uses the current selection as the "Find" field in Find and Replace (CtrlE,CtrlH)