程序员必备编译器 IntelliJ IDEA使用指南(长期更新,
一.Idea必要配置
1.关闭拼写检查:
Setting->Editor->General->Code Style->Inspections

取消这两个选项即可。
2.隐藏没用的文件:


修改为:
*.hprof;*.iml;*.pyc;*.pyo;*.rbc;*.yarb;*~;.DS_Store;.classpath;.git;.hg;.idea;.myeclipse;.mymetadata;.project;.settings;.svn;CVS;__pycache__;_svn;vssver.scc;vssver2.scc;.springBeans;.tern-project;.gitignore;
3.优化代码提示:代码提示不区分大小写
Setting->Editor->General->Code Completion
下拉窗选择None。

4.自动import类型:
4.1、勾选这两项
Setting->editor->general->Auto Import

4.2、自动导包,并删除没用的包(新版本)

5.同时管理多个项目
把 IDEA 项目看成工作空间,IDEA 模块看成项目,就可以实现一个窗口中管理多个项目。



由此创建的可以理解为myeclipsede一个工作空间:


通过这里来创建项目:(则可以同时管理多个项目)

管理空间的多个项目也可以移除:(和meclipse一样并不会删除项目)

6.创建maven项目:
在这里创建是为了管理多个项目,和管理单个项目创建的后续步骤相同:

*配置jdk
创建项目时首先配置jdk:

选择本地jdk

若为java项目直接选择maven

若为web项目需要勾选webapp:

Next

*单独配置jdk:
File->Project Structure->SDKs

*配置maven
接下来配置maven相关的东西:
首先选择使用本地的maven或者默认使用idea自带的

然后配置settings.xml配置文件:
下面的仓库路径会根据setting,xml文件自动生成

接下来一定要添加这一个配置,不然idea构建项目会卡很久

然后ok->Next->finsh->ok
*单独配置maven:
Setting->Build,Execution,Deployment->Build Tools->Maven

7.导入maven项目

选择要导入的项目:

选择maven

选择全局 profiles

这里也可以进行相关的maven配置:

Next->finsh
8.*配置tomcat

或者

添加本地tomcat




设置tomcat名称

*单独配置tomcat:
Setting->Build,Execution,Deployment->Application Servers

9.部署运行项目


选择需要部署的项目

设置访问路径(一般和项目名相同)

部署好后可以在这里看到

运行:

选择这两处(run/debug)都可以

启动日志会在这里输出

项目运行日志会在这里显示

10.其他优化:
(1).如何取消文件自动保存
Settings -> Appearance&Behavior -> System Settings标签项里
取消“Synchronize file on frame activation” 和“Save files on framedeactivation”的选择
同时我们选择"Save files automatically", 并将其设置为30秒,这样IDEA依然可以自动保存文件,也就是在30s内不会帮你自动保存文件,需要手动ctrl+s保存,超过30s会自动帮你保存。

如果想让修改时,在文件右边显示*号标志,Settings -> Editor –> General ->Editor Tabs
选中"Mark modifyied tabs with asterisk"

(2).如何让代码编辑区显示行号
Settings->Editor->Appearance标签项,勾选Show line numbers

(3).如何让IntelliJ IDEA启动的时候不打开工程文件
Settings -> Appearance&Behavior -> System Settings标签项里去掉Reopen last project on startup即可

(4).去掉烦人的indent提示

如何去掉呢?
打开IDEA 的preferences|Editor|Code Style,
去掉下图中的两个勾选:

(5).去掉框架检查提示

如何去掉框架的检查提示呢?

(6).自定义注释模板
我们创建一个java文件时,会在类的上面自动添加注释,包括作者和日期.
其实我们可以定制这个自动添加的注释:

修改前:

修改为:

二.常用快捷键及设置:
1.首先修改模版为eclipse的模版快捷键:
Settring->keyMap

2.创建getter,setter等(alt+shift+s)方法声明
快捷键:alt+insert
右键:


修改为eclipse一样的alt+shift+s(修改的时候也可以保留之前的,则两个快捷键都可以使用)

3.快速修复(ctrl+1)

修改为和eclipse一样(ctrl+1)
Settring->keyMap
搜索intent

移除掉其他的

类似于这样的问题ctrl+1就可以解决了

4.生成if..else, for, try..cath (alt+shift+a)

Atl+shift+z 和显卡驱动的快捷键冲突 ,修改为alt+shift+a
这样的效果:

5.配置联想功能快捷键(Alt+/)
添加alt+/

6.快速生成返回值

添加ctrl+2

7.快速生成main方法

改成:main

8.修改打印语句快捷键(默认是sout,可以将其改成sys)

改成sys:

9.for、foreach(itar为根据array数组生成for循环,itli为根据list集合生成for循环,iter为根据list集合生成foreach循环)

改成for

三.转移idea c盘配置文件
安装idea时会在c盘用户目录下创建:

Idea的安装目录中bin目录下的idea.properties配置文件里面是关于idea的一些配置

1.找到索引目录
win10系统下默认路径:C:\Users\asus\.IntelliJIdea2016.2
2.*复制或剪切到新的你想要的盘下
找到IntelliJ IDEA安装目录中配置文件(建议备份)
本人安装路径:D:\Work\IntelliJ IDEA 2016.2.5\bin\idea.properties
3.修改idea.properties配置文件
修改前:

修改后:

4.缓存索引清除
项目长期不用,记得清除缓存索引:

四.内存优化:

idea.exe.vmoptions原始配置文件:

idea.exe.vmoptions配置文件修改后:

idea64.exe.vmoptions原始配置文件:

idea64.exe.vmoptions配置文件修改后:

五.解决idea控制台中文乱码:

修改为:

六.Intellij IDEA设置忽略部分类编译错误(同时解决tomcat启动特别慢的问题)
有些时候我们的项目中有些错误,但这些错误并不影响项目的整体运行(或许是没有使用到),默认情况下idea是无法通过编译的,因此也就无法部署运行,要达到正确运行项目的目的需要作一些设置才行。
设置Intellij IDEA忽略部分类编译错误
设置很简单,只需要两步即可。
1、设置Java编译器

如上图所示,Ctrl+Alt+S快捷键打开“Settings”对话框,找到设置中的“Java Compiler”设置,将“User compiler”设置由“Javac”改为“Eclipse”;然后在下面的“Eclipse Options”中将“Proceed on errors”选项勾选上。
2、设置Run/Debug Configurations
接下来打开“Run/Debug Configurations”对话框,定位到你的项目启动配置(我这里是Web项目,Web Server为Tomcat7),将“Before launch”设置为“Make,no error check”(默认应该是Make),应用即可。
如下图所示:

通过上面两步设置,虽然在编译过程仍然有错误输出,但idea已经可以忽略掉编译过程的错误了。
为什么要在Intellij IDEA中使用Eclipse编译器
如果你使用Intellij Idea,你应该考虑使用Eclipse编译器来代替Javac。你的项目所使用的编译器可在IDE的设置页面更改。

需要注意,如果你使用的是Java8,只有Intellij 14及更高版本才会有可供选择的Eclipse编译器选项。
与Javac不同的是,Eclipse编译器被设计为IDE内部优先使用的编译器,因此提供了一些特性,使它更适合开发使用:
1、Proceed on errors
项目源代码的某一部分包含编译时错误是完全有可能的,然而这时你需要快速作一些测试来检测你的另一部分代码是否工作正常。
如果使用Javac编译器,你除了在执行之前修复所有错误之外没有其它的选择。然而Eclipse编译器却可以不管这些允许你执行,其目的在于总是生成一个可运行的二进制文件;如果你的代码触及到编译时错误,Eclipse编译器会招聘一个运行时异常。
想要启用这个特性,你需要:
1.1、在编译器设置页面选中“Proceed on errors”

1.2、在运行配置中用“Make, no error check”替换“Make”

2、增量编译
Eclipse编译器设计为运行于IDE后台,因此原生支持增量编译。这就意味着它可以只编译自上次编译以来有改动的代码块,因此编译比较快速。
3、并行编译
不像Javac编译器,Eclipse编译器可以利用CPU多核加快编译速度。
4、关于idea错误提示:
解决:不自动报错,只有编译或者鼠标点进之后才报错

结论
显而易见,在IDE内部没有什么理由再继续使用Javac编译器,希望Jetbrains公司会在未来版本的Intellij IDEA将Eclipse编译作为默认的编译器。
七.idea的bug调试:
Debug的时候调试功能必不可少,各个集成环境调试的思想和步骤肯定是一样的,只不过快捷键和图标不太一样而已。借着记录Intellij Idea的调试快捷键和图标含义,总结一下常用的调试功能。
Intellij Idea的编译和调试快捷键总结如下:
· shift+F10:编译

· shift+F9:调试

按下调试后,在Intellij下方出现如下的界面

· F9:调试窗口的小三角

,执行到下一个断点。
· shift+F8:逐过程step over(如果当前行有方法调用,这个方法将被执行完毕返回,然后到下一行)

shift+F7:逐语句step into向下执行一行。如果该行有自定义方法,则运行进入自定义方法(不进入官方类库的方法)

alt+shift+F7:Force step into调试的时候能进入任何方法。

alt+shift+F8:step out,确定某个方法没有问题时,跳出该方法

Drop Frame:返回某个方法的调用处重新执行

ctrl+shift+F8:view breakpoints查看断点

,可以设置一些属性,比如

这里可以设置x>1,表示x>1时暂停程序,用在对【循环】的调试比较方便
在此处

右键点击x可以【set value】,在调试时直接设置x的值,用在对【条件语句】的调试比较方便
官方文档
以上介绍的,只是IntelliJ IDEA众多功能中的冰山一角,想要了解更多,请进一步参考官方文档:
https://www.jetbrains.com/idea/documentation/
https://www.jetbrains.com/idea/help/intellij-idea-quick-start-guide.html
另外官网上也提供了很多的视频教程,其中有不少小技巧。
最后,在IntelliJ IDEA专题中还有非常不错的文章,笔者做了简单的文章收录(排名按专题热门🔥顺序):
Java程序员必备的Intellij插件(长期更新,截止到2018-05-03)
Maven 的 单模块 / 多模块 之 Spring MVC + Spring + Mybatis 项目视频讲解(基于 IntelliJ IDEA)

持续更新,未完待续......
欢迎小伙伴们提出宝贵意见!