Is there a keyboard shortcut in Pycharm for renaming a specific variable?

Deadly 提交于 2019-12-04 11:05:35

问题


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!


回答1:


Highlight your old_name and hit Shift+F6




回答2:


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.



来源:https://stackoverflow.com/questions/39746405/is-there-a-keyboard-shortcut-in-pycharm-for-renaming-a-specific-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!