您应该知道的7个最关键的IntelliJ IDEA键盘快捷键

Although there are lots of great alternatives, the family of Jetbrains editors has a huge fanbase. There are several IDE’s based on the Jetbrains IntelliJ platform: Intellij IDEA, Android Studio, PyCharm, WebStorm, PhpStorm, CLion, GoLand, Rider, etcetera!

尽管有很多不错的选择,但是Jetbrains编辑器家族拥有巨大的支持者。 有几种基于Jetbrains IntelliJ平台的IDE:Intellij IDEA,Android Studio,PyCharm,WebStorm,PhpStorm,CLion,GoLand,Rider等!

It pays to learn the most important shortcuts in these editors, and I believe these 7 are the most important ones. They will save you a considerable amount of time!

在这些编辑器中学习最重要的快捷键很有意义,我相信这7个是最重要的快捷键。 它们将为您节省大量时间!

1.选择代码的增加/减少部分 (1. Select increasing / decreasing sections of code)

Windows, Linux: Ctrl + W / Shift + Ctrl + WMac: ⌥ + ↑ and ⌥ + ↓

Windows,Linux: Ctrl + W / Shift + Ctrl + W Mac: ⌥+↑⌥+↓

Image for post

You can select increasing or decreasing sections of code near the cursor by pressing Ctrl + W or Ctrl + Shift + W respectively. The editor will smartly detect the bounds of a selection that is useful. This one is super useful when you need to indent or delete an entire section of code.

您可以分别通过按Ctrl + WCtrl + Shift + W来选择在光标附近增加或减少代码段。 编辑器将巧妙地检测出有用的选择范围。 当您需要缩进或删除整个代码段时,这一段超级有用。

2.应用修正或更正 (2. Apply a fix or correction)

All platforms: Alt + Enter

所有平台: Alt + Enter

Image for post
Alt + enter shows suggestions to fix a problem (screenshot by author)
Alt + Enter显示解决问题的建议(作者截屏)

If you only learn one shortcut, it must be Alt + Enter. It shows suggestions to fix a problem. You can select one of the fixes with the arrow keys and hit enter to apply it directly.

如果您仅学习一种快捷方式,则必须为Alt + Enter 。 它显示了解决问题的建议。 您可以使用箭头键选择一种修补程序,然后按Enter键直接应用它。

As an extra speedy option, shift +Alt + Enter applies the first suggestion. Since IntelliJ will order the suggested fixes by most likely applicability, this is often enough!

作为一种额外的快速选择, Shift + Alt + Enter将应用第一个建议。 由于IntelliJ将按照最可能的适用性对建议的修复程序进行排序,因此通常就足够了!

3.转到下一个错误,警告或建议 (3. Go to the next error, warning, or suggestion)

All platforms: F2

所有平台:F2

Image for post
F2 takes you to the next error, warning, or suggestion (screenshot by author)
F2带您进入下一个错误,警告或建议(作者截屏)

With this key, you’ll go to the next error, warning, or suggestion. This one works nicely in combination with Alt + Enter. Use it to navigate inside the current file and fix all problems, one by one.

使用此键,您将转到下一个错误,警告或建议。 与Alt + Enter结合使用时,此功能可以很好地工作。 使用它可以在当前文件中导航并一一解决所有问题。

4.转到声明 (4. Go to the declaration)

Windows, Linux: Ctrl+BMacOS: ⌘B

Windows,Linux: Ctrl + B MacOS: ⌘B

Image for post
Ctrl + B navigates to the declaration or shows usages (screenshot by author)
Ctrl + B导航到声明或显示用法(作者截屏)

To go to the declaration of a symbol, press Ctrl + B. For example, pressing this on a variable will take the cursor to the variable declaration. Using it on a class name will open a new tab and take you to the class file. With ⌥ + ⌘ + B (MacOS) or Ctrl+Alt+B (Windows/Linux), you can navigate to an implementation too.

要转到符号的声明,请按Ctrl +B。例如,在变量上按此键会将光标移到变量声明。 在班级名称上使用它会打开一个新选项卡,并将您带到班级文件。 使用⌥+⌘+ B (MacOS)或Ctrl + Alt + B (Windows / Linux),您也可以导航到实现。

5.打开项目窗口 (5. Open project window)

Windows, Linux: Alt+1MacOS: ⌘ + 1

Windows,Linux: Alt + 1 MacOS: ⌘+ 1

How often do you use your mouse to navigate your project inside the project window on the left? I bet it’s a lot.

您多久使用一次鼠标在左侧的项目窗口中浏览项目? 我敢打赌,这很多。

With Alt + 1, you can open the project window and put the focus in there too. You can navigate the project tree using your arrow keys, and search by simply starting to type what you’re looking for. When you’re done, use ESC to go back to the editor.

使用Alt + 1 ,您可以打开项目窗口并将焦点也放在其中。 您可以使用箭头键浏览项目树,然后只需开始输入要查找的内容即可进行搜索。 完成后,使用ESC返回编辑器。

6.将焦点放回编辑器/取消更改 (6. Put the focus back to editor / Cancel changes)

All platforms: ESC

所有平台: ESC

This one works nicely in combination with other shortcuts, like Alt + 1 from above. It put the focus back to the editor, no matter what tool window is open. In addition, the escape key allows you to close any popup without applying changes.

与其他快捷方式(例如上面的Alt + 1)结合使用时,此功能可以很好地工作。 无论打开了哪个工具窗口,它都将焦点放回到编辑器上。 此外,使用退出键可以关闭任何弹出窗口,而无需应用更改。

7.注释掉一行或选择的代码 (7. Comment out a line or selection of code)

Windows, Linux: Ctrl + /MacOS: ⌘ + /

Windows,Linux: Ctrl + / MacOS: ⌘+ /

Image for post
Ctrl + / (screenshot by author) Ctrl + /注释掉当前行或所选内容(作者截屏)

If you want to temporarily comment out a section of code, you can do so by first selecting the section (remember to use Ctrl + W / Shift + Ctrl + W) and then hitting Ctrl + /.

如果要暂时注释掉一段代码,可以先选择该部分(记住使用Ctrl + W / Shift + Ctrl + W ),然后按Ctrl + /来注释掉。

If you want to comment out the current line of code, simply hit Ctrl + / too — no selection needed.

如果您想注释掉当前代码行,也只需按Ctrl + / -无需选择。

Thanks for reading.What’s your most-used shortcut? Please share it in the comments!

感谢您的阅读。您最常用的快捷方式是什么? 请在评论中分享!

翻译自: https://levelup.gitconnected.com/7-most-crucial-intellij-android-studio-keyboard-shortcuts-6b08ffffcbc4

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值