I'm using Pycharm for Python coding, and I want to change the name of a specific variable all over the code. is there any keyboard shortcut for this operation?
In Matlab I can use ctrl + shift.
For example:
old_name=5
x=old_name*123
will become:
new_name=5
x=new_name*123
without the need to change both of the old_name
references.
Thanks!
Simply put your cursor on a symbol and use Refactor | Rename ( Shift-Ctrl-Alt-T, 1 Win/Linux, Ctrl-T, 1 macOS.) Provide the new name, preview the places it found, and select Do Refactor . Change your mind? Refactoring is done as a single editor transaction, meaning Undo reverts all the places that were renamed.
Right-click the variable or function name and then click Rename.
Visual Studio Code is Ctrl + Shift + L and begin typing. Sublime/Atom are alt + F3. Show activity on this post. If you're using the PyCharm IDE use Mayus + F6 on the variable that you want change and write the new name variable.
Do one of the following: On the main Refactor menu or from the context menu of the selection, choose the desired refactoring or press the corresponding keyboard shortcut (if any). From the main menu, choose Refactor | Refactor This, or press Ctrl+Alt+Shift+T , and then select the desired refactoring from the popup.
Highlight your old_name
and hit Shift+F6
I don't know about a shortcut for this special purpose, but I simply use Ctrl+R to replace the old variable names with new ones. You can also set settings such as Match case, Regex or In selection.
Note that this won't work, if you have a variable name including another variable name:
var1 = 0
var1_s = "0"
Replacing var1
to xy
would result in :
xy = 0
xy_s = "0"
But that also forces you to do consistent and clear variable naming.
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