前言
工欲善其事
必先利其器
最近受部门的邀请,给入职新人统一培训IDEA,发现有很多新人虽然日常开发使用的是IDEA,但是还是很多好用的技巧没有用到,只是用到一些基本的功能,蛮浪费IDEA这个优秀的IDE。 同时,在这次分享之后,本人自己也学习到了一些新的使用技巧,所以借着这次机会,一起分享出来。希望可以帮到一些人。
基于的 IDEA 版本信息:IntelliJ IDEA 2018.2.2 (Ultimate Edition)
知识点概览:
- 高效率配置
- 日常使用 必备快捷键(★★)
- 查找
- 跳转切换
- 编码相关
- 代码阅读相关
- 版本管理相关
- 编码效率相关(★★)
- 文件代码模板
- 实时代码模板
- 其他
- 代码调试 源码阅读相关(★★★)
- 视图模式
- 代码调试
- ...
- 插件方面
- 插件的安装与使用
- 插件推荐
- 参考
2019-08-09 UPDATE
[插件推荐]增加图片描述,增加插件内容。阅读更友好。
高效率配置
1. 代码提示不区分大小写Settings -> Editor -> General -> Code Completion
![68dbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p04.5ceimg.com/content/68dbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
(低版本 将 Case sensitive completion 设置为 None 就可以了)
2. 自动导包功能及相关优化功能Settings -> Editor -> General -> Auto Import
![6fdbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p05.5ceimg.com/content/6fdbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
3. CTRL + 滑动滚轮 调整窗口显示大小Settings -> Editor -> General -> Change font size (Zoom) with Ctrl+Mouse wheel
![77dbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p04.5ceimg.com/content/77dbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
选择之后,就可以通过CTRL+滑动滚轮的方式,调整编辑器窗口的字体大小
4. tab 多行显示
这点因人而异,有些人喜欢直接取消所有tab,改用快捷键的方式,我屏幕比较大,所以喜欢把tab全部显示出来。Window -> Editor Tabs -> Tabs Placement
,取消勾选 Show Tabs In Single Row
选项。
![7adbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p02.5ceimg.com/content/7adbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
效果如下:
![7ddbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p01.5ceimg.com/content/7ddbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
5. 代码编辑区显示行号Settings -> Editor -> General -> Appearance
勾选 Show Line Numbers
![80dbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p05.5ceimg.com/content/80dbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
![86dbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p03.5ceimg.com/content/86dbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
日常使用 必备快捷键(★★)
查找
![88dbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p05.5ceimg.com/content/88dbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
跳转切换
![8bdbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p05.5ceimg.com/content/8bdbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
编码相关
![8ddbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p05.5ceimg.com/content/8ddbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
代码阅读相关
![90dbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p04.5ceimg.com/content/90dbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
版本管理相关
![92dbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p02.5ceimg.com/content/92dbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
编码效率相关(★★)
文件代码模板Settings -> Editor -> File and Code Template
![93dbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p02.5ceimg.com/content/93dbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
在这里可以看到IDEA所有内置的文件代码模板,当你选择某个文件生成时,就会按照这里面的模板生成指定的代码文件。
另外,你可以在这里设置文件头。
![94dbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p02.5ceimg.com/content/94dbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
设置之后,效果如下
![a3dbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p05.5ceimg.com/content/a3dbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
实时代码模板
IDEA提供了强大的实时代码模板功能,并且原生内置了很多的模板,比如,当你输入sout
或者psvm
,就会快速自动生成System.out.println();
和public static void main(String[] args) {}
的代码块。
![a7dbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p02.5ceimg.com/content/a7dbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
![aadbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p01.5ceimg.com/content/aadbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
这些的模板可以在Settings -> Editor -> Live Templates
看到。使用者可以按照自己的使用习惯来熟悉相关的代码模板。
![addbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p03.5ceimg.com/content/addbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
定制代码模板
IDEA也提供自己定制实时代码模板的功能。
- 创建自己的模板库
- 创建定制的代码模板
![b0dbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p04.5ceimg.com/content/b0dbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
图中的MyGroup
就存放着我自己定义的代码模板。
其他
CRTL+ALT+T
![b2dbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p04.5ceimg.com/content/b2dbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
Ctrl + Alt + T
提供的是代码块包裹功能 - Surround With。可以快速将选中的代码块,包裹到选择的语句块中。
本地历史版本
IDEA 自带本地版本管理的功能,能够让你本地编写代码变得更加的安心和方便。
![b3dbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p05.5ceimg.com/content/b3dbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
代码调试 源码阅读相关(★★★)
视图模式
![b5dbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p01.5ceimg.com/content/b5dbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
IDEA提供两种特殊的视图模式,
- Presentation Mode - 演示模式,专门用于Code Review这种需要展示代码的场景
- Distraction Free Mode - 禅模式,专注于代码开发
代码调试
1. 条件断点
IDEA 可以设置指定条件的断点,增加我们调试的效率。
![b8dbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p03.5ceimg.com/content/b8dbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
2. 强制返回
IDEA 可以在打断点的方法栈处,强制返回你想要的方法返回值给调用方。非常灵活!
![badbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p01.5ceimg.com/content/badbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
![bbdbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p02.5ceimg.com/content/bbdbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
3. 模拟异常
IDEA 可以在打断点的方法栈处,强制抛出异常给调用方。这个在调试源码的时候非常有用。
![bddbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p04.5ceimg.com/content/bddbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
4. Evaluate Expression
IDEA 还可以在调试代码的时候,动态修改当前方法栈中变量的值,方便我们的调试。
![c4dbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p05.5ceimg.com/content/c4dbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
插件方面
插件安装File -> Setting -> Plugin
插件安装,可以直接在IDEA的插件库中实时搜索安装。browse plugin repository
对于网络不好的用户,可以登录官方插件仓库地址:plugins.jetbrains.com/idea,下载压缩包之…install from disk
插件推荐
本人日常开发中使用的插件
Alibaba Java Coding Guidelines
阿里Java编程规约插件
FindBugs
代码缺陷扫描
![c9dbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p01.5ceimg.com/content/c9dbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
![cbdbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p03.5ceimg.com/content/cbdbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
PMD
代码缺陷扫描
InnerBuilder
builder模式快速生成
![cedbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p05.5ceimg.com/content/cedbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
lombok plugin
lombok 插件
maven helper
maven 依赖管理助手 ,解析maven pom结构,分析冲突;
![d0dbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p01.5ceimg.com/content/d0dbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
![d2dbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p02.5ceimg.com/content/d2dbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
Rainbow brackets
让代码中的括号更具标识性
![d3dbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p04.5ceimg.com/content/d3dbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
String Manipulation
String相关辅助简化,搭配 CTRL+W 、ALT+J等文本选择快捷键使用
![d6dbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p03.5ceimg.com/content/d6dbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
Translation
翻译插件,阅读源码必备
![d7dbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p03.5ceimg.com/content/d7dbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
![d8dbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p04.5ceimg.com/content/d8dbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
GenerateAllSetter
GenerateAllSetter
![dadbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p05.5ceimg.com/content/dadbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
Key Promoter X
对你的鼠标操作进行 快捷键提示
![dbdbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p05.5ceimg.com/content/dbdbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
GenerateSerialVersionUIDAlt
+ Insert
快速生成SerialVersionUID
![v2-089932934f1d13baa25117d77d643332_b.jpg](http://img-03.proxy.5ce.com/view/image?&type=2&guid=eedbc0b3-6d13-eb11-8da9-e4434bdf6706&url=https://pic3.zhimg.com/v2-089932934f1d13baa25117d77d643332_b.jpg)
GsonFormat
![e0dbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p04.5ceimg.com/content/e0dbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
RestfulToolkit
- 快速跳转到Restful Api处( use: Ctrl(Command) + or Ctrl + Alt + N )
- 展示Resultful 接口结构
- http 简单请求工具
![e2dbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p02.5ceimg.com/content/e2dbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
![e4dbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p05.5ceimg.com/content/e4dbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
Material Theme UI
本人自用的主题就是这个。
![e7dbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p04.5ceimg.com/content/e7dbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
MyBatis Log Plugin
把 Mybatis 输出的sql日志还原成完整的sql语句,看起来更直观。
![e9dbc0b3-6d13-eb11-8da9-e4434bdf6706.png](http://p03.5ceimg.com/content/e9dbc0b3-6d13-eb11-8da9-e4434bdf6706.png)
Free Mybatis
MyBatis 免费的插件
参考
- github.com/judasn/Inte…
作者:Richard_Yi
链接:https://juejin.im/post/5d47f4e851882534d152a206
来源:掘金
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。