Java IntelliJ 在多行中替换变量名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27249226/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 04:03:00  来源:igfitidea点击:

IntelliJ replace variable names in multiple lines

javareplaceintellij-idea

提问by daiyue

I am wondering is there a shortcut that can replace a variable name with a new name on multiple lines in the current Javafile for IntelliJ. Is it just simply doing a find and replace operation, but it can't really solve the problem obviously.

我想知道是否有一个快捷方式可以在当前Java文件的多行中用新名称替换变量名称IntelliJ。是不是只是简单的做一个查找替换操作,显然并不能真正解决问题。

采纳答案by Insomniac631

Try to set cursor on variable and use shortcut Shift-F6- after that there are dialog frame for change name of variable and it changes all occurences of variable to setted name.

尝试将光标设置在变量上并使用快捷方式Shift-F6- 之后有用于更改变量名称的对话框,并将所有出现的变量更改为设置的名称。

Also, you can use shortcut Ctrl-Shift-Rfor replacing any word in project, it is useful if you working with huge project or your variable appears in config files.

此外,您可以使用快捷方式Ctrl-Shift-R替换项目中的任何单词,如果您使用大型项目​​或您的变量出现在配置文件中,这将非常有用。

回答by Sashini Hettiarachchi

Steps:

脚步:

1: Put the cursor on the variable ex:

1:将光标放在变量ex上:

enter image description here

enter image description here

  1. Press shift+f6
  2. Enter the name you want in the appeared dialogue box
  1. shift+f6
  2. 在出现的对话框中输入你想要的名字

ex:

前任:

enter image description here

enter image description here

  1. Hit the Refactorbutton
  1. 点击重构按钮