IntelliJ IDEA使用总结

官方链接:

下载: https://www.jetbrains.com/idea/download/other.html

文档: 官方帮助文档

File —> Settings… 对当前工程设置一定有效,对新建工程不一定有效

File —> New Projects Settings 对新建工程设置有效

idea 没有工作空间的概念;eclipse 每新建一个工作空间,都需要对该工作空间下的工程重新设置。

settings.zip

2020.3.3 配置: settings.zip.gz

IDE高级配置

https://www.jetbrains.com/help/idea/tuning-the-ide.html

1
2
3
4
# 平台属性
IDE_HOME/bin/idea.properties
# JVM选项。IDEA在Java虚拟机(JVM)上运行,它具有控制其性能的各种选项。用于运行IDEA的默认选项在IDE安装目录中指定
IDE_HOME/bin/idea64.exe.vmoptions

注意:不要更改默认配置文件,因为它会在 IntelliJ IDEA 更新时被替换。此外,对于 macOS,编辑此文件会违反应用程序签名。

IDEA配置优先级:

1
2
3
4
1、环境变量(IDEA_PROPERTIES、IDEA_VM_OPTIONS)
2、Toolbox应用中的配置
3、配置目录(主菜单选择 Help | Edit Custom ....会自动创建,Windows目录C:\Users\Administrator\AppData\Roaming\JetBrains\IntelliJIdeaxxxx.x)
4、默认配置文件(IDE_HOME/BIN/idea.properties)

IDE升级

1、解压 ideaIU-xxxx.x.x.win.zip

2、修改配置

默认配置

1
2
3
4
5
# config配置位置
C:\Users\Administrator\AppData\Roaming\JetBrains

# system配置位置
C:\Users\Administrator\AppData\Local\JetBrains

修改配置 D:\Program Files\ideaIU-xxxx.x.x.win\bin\idea.properties ,重启生效。注意:反斜杠无效

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#---------------------------------------------------------------------
# Uncomment this option if you want to customize path to IDE config folder. Make sure you're using forward slashes.
#---------------------------------------------------------------------
# idea.config.path=${user.home}/.IntelliJIdea/config
idea.config.path=D:/Program Files/ideaIU-xxxx.x.x.win/.IntelliJIdea/config # windows中反斜杠无效

#---------------------------------------------------------------------
# Uncomment this option if you want to customize path to IDE system folder. Make sure you're using forward slashes.
#---------------------------------------------------------------------
# idea.system.path=${user.home}/.IntelliJIdea/system
idea.system.path=D:/Program Files/ideaIU-xxxx.x.x.win.IntelliJIdea/system

#---------------------------------------------------------------------
# Uncomment this option if you want to customize a path to the user-installed plugins directory.
#---------------------------------------------------------------------
# idea.plugins.path=${idea.config.path}/plugins
idea.plugins.path=${idea.config.path}/plugins

#---------------------------------------------------------------------
# Uncomment this option if you want to customize a path to the logs directory.
#---------------------------------------------------------------------
# idea.log.path=${idea.system.path}/log
idea.log.path=${idea.system.path}/log

3、导入 settings

快捷键

File -> Settings… -> Keymap

为了不发生快捷键冲突,请在美式键盘下操作:

快捷键 功能
Alt+Enter 导包,自动补全代码
Ctrl+Space 代码提示
Ctrl+Shift+U 大小写转化

列选择模式(多行编辑)

鼠标右键->Column Selection Mode 或 Alt+Shift+Insert

配置代理

官方HTTP代理: https://www.jetbrains.com/help/idea/settings-http-proxy.html

注意:只会代理 IDEA 上的工具,Java 项目中的 DB、MQ 等连接的代理需要配置 JVM 参数(详见 v2ray 章节)

手动代理配置

不使用代理的域名列表示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
*.com
*.org
192.168.*
127.0.0.1
::1
localhost

/*
*.jetbrains.com
*.github.com
*.google.com
*.googleapis.com
*.baidu-int.com
*.baidu.com
*/

image-20200413212136997

image-20200413212204691

自动检测代理设置

————–没测成功————–

将代理工具的 系统代理模式 改为 PAC 模式

image-20200413215317972

Windows设置 —> 网络和 Internet —> 代理,脚本地址示例:

http://127.0.0.1:1080/pac?auth=6pGf8fJsS-ZO4o3hrfK7&t=202004132149393874

image-20200413215935219

全局搜索

Edit –> Find –> Find in Files…

全局替换

Edit –> Find –> Replace in Files…

取消 idea 启动时重新打开上一个项目

File -> Appearance & Behavior -> System Settings

image-20210314135232012

配置 JDK

maven-compiler-plugin 插件需要指定 maven 编译的 jdk 版本。

image-20200413221738324

配置 Maven 本地仓库

image-20200711145559349

image-20200711145919446

配置 Maven VM Options

使用 maven-javadoc-plugin 生成 JavaDoc 时控制台输出乱码解决办法:

1
-Dfile.encoding=GBK

image-20201016154435175

切记一定是GBK。即使用UTF-8的话,依然是乱码,这是因为Maven的默认平台编码是GBK,如果你在命令行中输入mvn -version的话,会得到如下信息,根据Default locale可以看出:

image-20201016154852184

Settings for New Project…

设置 UTF-8 编码

当前工程文件编码

File -> Settings -> Editor -> File Encodings

image-20200423180038102

新建工程文件编码

File -> New Projects Settings -> Settings for New Projects

.idea文件夹

将项目中的 .idea文件夹 中的 encodings.xml 文件中的编码格式改为 UTF-8

命令行参数编码

File -> Settings -> Build,Execution,Deployment -> Compiler -> Java Compiler

设置 Additional command line parameters选项为 -encoding utf-8

image-20200423180653151

Tomcat 编码

打开 Run/Debug Configuration,选择 tomcat。

然后在 Server > VM options 设置为 -Dfile.encoding=UTF-8 ,重启 tomcat。

image-20200423181128625

配置 Git

安装 Git 解压版,然后配置 idea 如下:

image-20200710204912954

配置 SVN

安装 Subversion 客户端图形化软件 TortoiseSVN:

image-20200717095541358

配置 idea 如下:

image-20200717100321295

版权设置

Settings -> Editor -> Copyright -> Copyright Profiles,点击 + 号新增,起个名字例如 Zhaolq,Copyright text 内容如下:

1
Copyright (c) Zhaolq Technologies Co., Ltd. 大约40亿年前-${today.year}. All rights reserved.

回到上级菜单选择 Default project copyright : Zhaolq 即可。

使用方式:
1、新建文件回自动添加。
2、在文件中使用快捷键 Alt + Insert ,选择 Copyright

New Projects Settings ….

注释格式化对齐

image-20210822142935345

方法声明参数格式化

image-20220206201645820

一行注释收起

image-20220206200525539

单行注释

单行注释的两个斜杠跟随在代码的头部并添加空格:

image-20201009152257215

image-20210925160127490

设置代码行宽

设置代码最大行宽,以及自动换行

image-20201103143320351

勾选 wrap on typing,即在编码时,超出最大行宽,则自动换行,或者采用下面这种方式,

在手动格式化的时候,进行自动换行。建议两个都设置

image-20201103144327417

隐藏 *.iml、.idea 等文件

点击File–>Settings–>Editor–> Flie Types,在 ignore files and folders 输入框添加内容:

1
.idea;*.iml;.gitignore;

image-20200706160101441

禁止import *

import 同一个包下多个类自动变成 *

File->Settings->Editor->CodeSyle->Java->Imports

image-20220206155725217

import内部类

配置见 import *

1
2
3
4
5
6
7
public class Test {
static class InnerTest {
public static InnerTest builder() {
return new InnerTest();
}
}
}
1
2
3
4
5
6
7
import com.zhaolq.Test.InnerTest; // 注意这里

public class Main {
public static void main(String[] args) {
InnerTest innerTest = InnerTest.builder();
}
}

import顺序

1
2
3
4
5
6
7
8
9
10
11
12
13
import java.*
<blank line>
import javax.*
<blank line>
import org.*
<blank line>
import com.*
<blank line>
import com.zhaolq.*
<blank line>
import all other imports
<blank line>
import static all other imports

image-20210822145019776

自动导包

新项目需要重新设置

image-20200708221909516

自动编译

新项目需要重新设置

新建工程设置: File -> New Projects Settings -> Settings for New Projects

image-20200715145808911

显示方法参数提示

image-20210529125024371

代码提示和补充功能

不区分大小写:

image-20201009144340637

鼠标滑轮修改字体大小

image-20201009145746718

固定字体大小

软分行

image-20201009153141967

Tab选项卡数量

image-20201009155415556

显示内存使用情况

双击shift,搜索show memory indicator并开启,点击还可以进行部分内存的回收。

image-20201009143544890

源码无法下载问题

idea 无法下载依赖包的source,使用 maven 下载 source

1
2
# 在对应项目pom.xml所在目录下执行以下命令:
mvn dependency:resolve -Dclassifier=sources

img

IDEA中xml文件头报错

1
URI is not registered (Settings | Languages & Frameworks | Schemas and DTDs)

中文翻译就是统一资源标识符没有注册,如下图:

img

需要把这个不被识别的统一资源标识符添加到IDEA中,步骤如下:

file –> settings… –> languages & frameworks –> Schemas and DTDs

image-20201002165655033

连续格式化

取消连续格式化两次,导致自定义换行符失效

image-20240822185003119

.editorconfig代码风格统一

https://intellijidea.com.cn/help/idea/editorconfig.html