2
Currently I do this with Find All
(Cntrl+F old_var
, alt+enter new_var
), but this replaces words in my comments and strings.
A comment in this answer suggested the PyRefactor plugin which requires rope. These tools seem to have defaults that are too heavy-handed for my purposes. I just want to refactor variable names in stand-alone python scripts with Sublime Text 3.
So in a script like
# Where did my hat go?
hat = 0
print(hat)
print("hat")
The hat
variable (not in strings nor comments) can be replaced with something else at the touch of a hotkey. No need for a special project folder/configuration, and nothing changed across multiple files. Unfortunately, Find All hat -> llama
does...
# Where did my llama go?
llama = 0
print(llama)
print("llama")
EDIT:
I appreciate @Toto's regex solution, but I'm not fluent in that yet and would like a method that works more consistently and is easier to remember. Is there a plugin (or can I write one?) that identifies all the globally defined and stated variables (arguments in function calls, etc), and allows for a simple Find and Replace?
1You can likely use a regex to see if the line starts with # – var firstName – 2018-09-12T19:15:05.883
Have you thought about using an IDE that makes refactoring like this much easier? I used to be loyal to Sublime, until I discovered JetBrains IDEs. – DrZoo – 2018-09-13T19:10:37.010