intellij 快捷方式_很酷的intellij想法快捷方式

本文介绍了IntelliJ IDEA中提高开发效率的几个实用快捷键,包括重命名(Shift+F6)、多光标(Alt+J)、书签(Ctrl+Shift+AnyKey)等,帮助开发者在更短的时间内完成更多工作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

intellij 快捷方式

I have used Netbeans, Eclipse, STS, and Intellij IDEA but Intellij has been my ultimate choice since my first use. It is one of the best IDE for developing applications. Compared to other IDEs, it provides strong support for autocomplete feature. The debugging feature in it is a lot easier and the User Interface is awesome. I just love it.

我曾经使用过Netbeans,Eclipse,STS和Intellij IDEA,但是自从首次使用以来,Intellij一直是我的最终选择。 它是用于开发应用程序的最佳IDE之一。 与其他IDE相比,它为自动完成功能提供了强大的支持。 它的调试功能要容易得多,并且用户界面很棒。 我就喜欢。

Using shortcuts helps us to do more in less time. I have my favorite IntelliJ IDEA shortcuts mentioned below.

使用快捷键可以帮助我们在更短的时间内完成更多工作。 我有下面提到的我最喜欢的IntelliJ IDEA快捷方式。

Note: I have GNOME as a keymap setting in my IDE.

注意:我在我的IDE中将GNOME作为键映射设置。

重命名(Shift + F6) (Rename (Shift + F6))

This is the most frequently used shortcut for me. It helps to rename the variables or methods’ names. Let’s see an example.

这是我最常用的快捷方式。 它有助于重命名变量或方法的名称。 让我们来看一个例子。

public List<String> getPaymentList(){
// logicreturn Collections.emptyList();
}

Your senior developer didn’t like the name of your method or let’s say Uncle Bob would hate you for this method name which is why you would like to change it. It had been used in twenty different places and you have to replace the name manually. Can you feel the pain? Go to the method declaration part of your code or to the method calling part, place your cursor to the method name and hit Shift + F6, and rename your method. Voila, you can see the changes being reflected in all the files.

您的高级开发人员不喜欢您的方法名称,或者说Bob叔叔讨厌您使用此方法名称,这就是您想要更改它的原因。 它已经在二十个不同的地方使用过,您必须手动替换名称。 你能感觉到疼痛吗? 转到代码的方法声明部分或方法调用部分,将光标置于方法名称上,然后按Shift + F6键,然后重命名您的方法。 瞧,您可以看到更改反映在所有文件中。

多光标(Alt + J) (Multi Cursor (Alt + J))

This is personally my favorite shortcut. It is also a shortcut to flex with junior developers. It helps us to multi-select the matching content. Consider the scenario, where you have this SQL file.

这是我个人最喜欢的快捷方式。 对于初级开发人员来说,这也是一种灵活的快捷方式。 它帮助我们多选匹配的内容。 考虑具有该SQL文件的方案。

INSERT INTO users(id, name, address, phone) VALUES (1, 'John', 'ktm', '122233');
INSERT INTO users(id, name, address, phone) VALUES (2, 'Tim', 'ktm', '122234');
INSERT INTO users(id, name, address, phone) VALUES (3, 'Tom', 'ktm', '122235');
INSERT INTO users(id, name, address, phone) VALUES (4, 'Lindy', 'ktm', '122236');
INSERT INTO users(id, name, address, phone) VALUES (5, 'Catherina', 'ktm', '122237');
INSERT INTO users(id, name, address, phone) VALUES (6, 'Bill', 'ktm', '122238');
// 1000 of lines

You have to add one more column in this SQL called user_type with static value USER, are you going to do it manually? Definitely, not. There might be other options for this use case as well, but I am going to demonstrate the power of Alt + J. In the first line, place your cursor before VALUES and select phone) and hit Alt+J multiple times and you can see the exact word phone) being selected. This is what it looks like:

您必须在此SQL中再添加一列名为user_type且具有静态值USER的列,是否要手动执行此操作? 当然不。 该用例可能还有其他选项,但是我将演示Alt + J的功能。在第一行中,将光标置于VALUES之前,然后选择phone),然后多次按Alt + J ,您可以看到确切的字词电话)被选中。 看起来是这样的:

Image for post

Move your cursor before ) and type , along with your column name i.e user_type. There you go, we unleashed the power of Alt + J. Also, we can unselect from the last by hitting Alt + Shift + J.

将光标移到)之前,然后输入,以及您的列名,即user_type。 在这里,我们释放了Alt + J的功能。此外,我们可以通过按Alt + Shift + J取消上一个的选择

Image for post

书签(Ctrl + Shift + AnyKey和Ctrl + AnyKey ) (Bookmark (Ctrl+Shift+AnyKey and Ctrl+AnyKey))

If you are working with multiple files, you might have to navigate between methods across different files. It will be a pain to go back and forth. Let’s say you are trying to fix a bug written by somebody else, you are already tired searching codes and you forgot the method name or class name you recently visited, it will be so infuriating. Adding a bookmark will help you to be more productive in such cases.

如果使用多个文件,则可能必须在不同文件之间的方法之间导航。 来回走很痛苦。 假设您正在尝试修复其他人编写的错误,您已经厌倦了搜索代码,并且忘记了最近访问的方法名或类名,这将非常令人生气。 在这种情况下,添加书签将有助于您提高工作效率。

You can hit Ctrl+Shift+AnyKey to set a bookmark. For eg: Ctrl+Shift+1. Intellij IDEA will show a bookmark icon.

您可以按Ctrl + Shift + AnyKey设置书签。 例如: Ctrl + Shift + 1 。 Intellij IDEA将显示一个书签图标。

Image for post

You can work with other files and if you feel like jumping into this code, you can hit Ctrl+AnyKey (Ctrl+1 in this case) and you will be returned to this method. It’s that easy. Similarly, you can remove the bookmark by hitting Ctrl+Shift+AnyKey.

您可以使用其他文件,并且如果您想跳入此代码,则可以按Ctrl + AnyKey(在这种情况下为Ctrl + 1) ,您将返回此方法。 就这么简单。 同样,您可以通过按Ctrl + Shift + AnyKey删除书签。

内联(Ctrl + Alt + N) (Inline (Ctrl+Alt+N))

I prefer deleting codes to writing codes. I love to refactor the code. This shortcut is used to inline the variable or method call. It’s mostly used while refactoring the code.

我更喜欢删除代码而不是编写代码。 我喜欢重构代码。 此快捷方式用于内联变量或方法调用。 它主要在重构代码时使用。

Customer customer = getCusomer();
createPaymentIntent(customer);

In the snippet like above, if it makes sense to you to inline getCustomer() method, then you can place your cursor to the customer object and hit Ctrl+Alt+N. It will inline the code and the result, then, looks like:

在上述代码段中,如果内联getCustomer()方法对您有意义,则可以将光标置于客户对象上,然后按Ctrl + Alt + N。 它将内联代码和结果,如下所示:

createPaymentIntent(getCusomer());

提取变量/方法/字段/常量/参数 (Extract Variable/Method/Field/Constant/Parameter)

This shortcut also makes refactoring easy.

此快捷方式也使重构变得容易。

Snippet-1:

片段1:

getCustomer(); //returns Customer Object

Select getCustomer() method and hit Ctrl+Alt+V to get the variable returned by the object. The result will be:

选择getCustomer()方法,然后按Ctrl + Alt + V获取对象返回的变量。 结果将是:

Customer customer = getCustomer();

Snippet-2:

片段2:

Customer customer = new Customer();
customer.setName("Customer");
customer.setAddress("Ktm");
customer.setMobile("9779852365321");

Let’s say, you want to refactor this piece of code into a method. You can select these blocks of codes and enter Ctlr+Alt+M in order to extract to a method. Intellij IDEA will show a popup where you can enter the name of the method along with the visibility (access modifiers).

假设您要将这段代码重构为一个方法。 您可以选择这些代码块,然后输入Ctlr + Alt + M以便提取到方法。 Intellij IDEA将显示一个弹出窗口,您可以在其中输入方法的名称以及可见性(访问修饰符)。

Likewise, Ctrl+Alt+P is for extracting the method parameter. Ctrl+Alt+C is for extracting a constant variable and Ctrl+Alt+F is for extracting a field variable.

同样, Ctrl + Alt + P用于提取方法参数。 Ctrl + Alt + C用于提取常量变量,而Ctrl + Alt + F用于提取字段变量。

实时模板 (Live Templates)

You can save time by using live templates for the code blocks you use repeatedly. Intellij Idea itself provides some live templates. Let’s check it out.

您可以通过对重复使用的代码块使用实时模板来节省时间。 Intellij Idea本身提供了一些实时模板。 让我们来看看。

  • psf: Type psf and hit Tab, public static final snippet will be generated.

    psf:输入psf并点击Tab,将生成public static final摘录。

  • psfs: Type psfs and hit Tab, public static final String snippet will be generated.

    psfs:键入psfs并单击Tab,将生成public static final String片段。

  • thr: Type thr and hit Tab, throw new snippet will be generated.

    thr:键入thr并单击Tab,将生成throw new代码段。

  • fori: Type fori and hit Tab, a for loop will be generated.

    fori:键入fori并点击Tab,将生成一个for循环。
  • iter: Type iter and hit Tab, a forEach loop will be generated.

    iter:输入iter并点击Tab,将生成一个forEach循环。

You can also define your custom live templates.

您还可以定义自定义实时模板。

Thanks a lot for reading my article. If you know other cool shortcuts, then feel free to add in the comments :)

非常感谢您阅读我的文章。 如果您知道其他很酷的快捷方式,请随时添加评论:)

翻译自: https://medium.com/@surajgautam077/cool-intellij-idea-shortcuts-d0c82db77dd2

intellij 快捷方式

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值