在 PHPStorm 中重命名文件而不重构
如何在 PHPStorm 中不重构快速重命名文件名?即使在我刚刚创建文件之后,PHPStorm 也会花费很长时间来搜索我的文件以了解其使用情况。
How do I quickly rename a file name without refactoring in PHPStorm? Even after I've just created the file, PHPStorm takes a long time to search through my files for its usage.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我快速重命名文件的方法是单击文件名并按 Shift-F6。将打开一个对话框,您可以立即键入文件的新名称,然后按回车/回车键完成重命名。
我发现这种技术很直观,因为您不必将鼠标移动到对话框窗口、键入新名称或单击任何内容进行确认。只要您所做的只是一个您知道是安全的重命名,您只需输入它即可。
我也喜欢这个功能,因为您仍然可以选择在进行更改之前快速预览更改。在这些情况下,当您重构可能对应用程序其余部分产生影响的内容时,您仍然可以启用“搜索引用”和/或“在注释和字符串中搜索”来获取整个辣酱玉米饼馅。 (我默认禁用这些选项。)
我同意您的观点,右键单击文件名,向下滚动到“重构”,选择“重命名”,然后输入新名称很麻烦,特别是在启用了安全检查的情况下。我发现 PhpStorm 开发人员似乎理解这些类型的问题,并且通常也会想到一种“更快的方法”来完成任务。
My technique for renaming files quickly is to single-click the file name and press Shift-F6. A dialog opens and you can immediately type the new name of the file and hit return/enter to complete the rename.
I find this technique intuitive because you don't have to move your mouse to the dialog window, type the new name, or click anything to confirm. As long as all you're doing is a rename that you know is safe, you just type it and go.
I also like this feature because you still have the option of quickly previewing the changes before they're made. And on those occasions when you are refactoring something with possible implications to the rest of your app, you can still enable "Search for references" and/or "Search in comments and strings" to get the whole enchilada. (I have those options disabled by default.)
I agree with you that right-clicking the file name, scrolling down to Refactor, selecting Rename, and then entering the new name is cumbersome, especially if the safe checks are enabled. I find that PhpStorm developers seem to understand these types of issues and usually have thought of a "faster way" to do things as well.
尽管
Refactor
| 不重构就无法做到这一点。重命名
通常非常快,您可以禁用搜索参考的选项。You can't do it without refactoring, though
Refactor
|Rename
is usually very quick and you can disable options to search for references.默认为Shift-F6。如果不重构,请禁用弹出窗口中的复选框。
我想像 Windows 默认那样使用 F2 进行文件重命名。
您可以创建F2的快捷方式。转到:
编辑
如果它不能立即工作,请重新启动PHPStorm。
Default is Shift-F6. For not refactoring, disable the checkboxes in the popup.
I wanted to use F2 for file renaming like Windows default.
You can make a shortcut for F2. Go to:
EDIT
If it does not work immediately, restart PHPStorm.
还有一个可用选项右键单击文件选择“在资源管理器中显示”,然后在 Windows 资源管理器中按 F2 重命名文件。它不会重构或影响项目中的任何其他文件。
There is also an option available Right-click on file select "Show In Explorer" and then in windows explorer rename file by F2. It will not refactor or effect any other file in your project.
这适用于 Linux 用户。
它取决于
zenity
,因此首先检查它是否安装在您的系统上,在控制台中运行:
zenity --version
如果它输出类似
3.18.1.1
的内容 - 那么就可以了。创建包含以下内容的文件
idea-rename.sh
:打开您的
Settings
>工具
>外部工具
,点击并填写如下表格
名称:
重命名
组:
文件
程序:
/bin/bash
参数:
/path/to/idea-rename.sh $FileDir$ $FileName$
工作目录:
$ProjectFileDir$
单击
确定
、应用
之后,您可以在文件菜单中看到新项目
当您单击
重命名
时,将打开对话框重命名后在某些情况下 phpstorm 不会同步文件,因此在路径中文件所在位置需要单击文件菜单“同步'路径'”
This will work for linux users.
It depends on
zenity
, so first check if it installed on your system,run in console:
zenity --version
If it output something like
3.18.1.1
- then it's ok.Create file
idea-rename.sh
with content below:Open your
Settings
>Tools
>External Tools
, click onand fill form as below
Name:
Rename
Group:
File
Program:
/bin/bash
Parameters:
/path/to/idea-rename.sh $FileDir$ $FileName$
Working Directory:
$ProjectFileDir$
Click
Ok
,Apply
After that you can see new item in your file menu
When you click on
rename
will opens dialogAfter rename in some cases phpstorm not sync files, so in path where located your file need to click in file menu "Synchronize 'path'"
我喜欢 Andrey Izman 的 答案,但 bash 脚本的复杂性让我感到惊讶。
所以我又做了一个:
绑定到 IDE 略有不同:
请注意
Arguments
设置中的差异:引号中的单个变量。另请注意,该脚本也可以独立使用(即不在 JetBrains IDE 中)。
I like Andrey Izman's answer, but the bash script surprised me with its complexity.
So I made another one:
Binding into IDE is slightly different though:
Note the difference in
Arguments
setting: single variable in quotes.Note also that this script can also be used standalone (i.e. not within the JetBrains IDE).