Sublime Forum

How to change same variable name

#1

example in python
name = " sublime"
print name
print name,name


In this case
I double click the first “name” variable and than anothers ‘name’ is blocked
and i change clicked ‘name’ to ‘full_name’ , just clicked variable change and anther ‘name’ not change
how to change same variable name ??

0 Likes

#2

The simplest way: put cursor on name, alt+f3 (select all), then type your new variable name.

In case there is multiple stuff named name but you don’t want to change them all: put cursor on name, ctrl+d every time you want to accept the selection and ctrl+k,ctrl+d if you want to skip the selection and go to the next. And once you are happy with your multiple selection, just type your new named.

And there might be other solutions involving language specific plugin allowing re-factoring, like Anaconda for python.

3 Likes

#3

Since this was one of the top results that comes up in google when I search for “sublime refactor rename”, I wanted to share that the SublimeText LSP plugin (+ an appropriate language server plugin) provides this sort of ‘smart rename / refactor’ functionality these days:

0 Likes

Renaming in Sublime Text
Refactor->Rename
Refactor variable name