转载

二十个 IntelliJ IDEA 实用配置(含类和方法注释模板)


原文链接https://onestar.newstar.net.cn/blog/60

欲善其事,必先利其器,本文将讲述IDEA 2020.2版本的一些基本配置,包括主题、编码、字体,包括类和方法注释模板配置讲解。

1、主题

File --> Settings --> Appearance & Behavior --> Appearance

image

2、JDK

File --> Project Structure --> SDKs

image

File --> Project Structure --> Project

image

3、字体大小、样式(两种方法,看自己喜好)

  1. 固定字体大小:File --> Settings --> Editor --> General --> Font

image

  1. 使用Ctrl+鼠标滚轮修改代码字体大小:File --> Settings --> Editor --> General

image

4、编码格式UTF-8

File --> Settings --> Editor --> File Encodings

image

5、智能提示不区分大小写

File --> settings --> Editor --> General --> Code Completion

image

6、关闭自动更新

File --> Settings --> Appearance & Behavior --> System Settings --> Updates

image

7、隐藏无关文件

File --> Settings --> Editor --> File Types

【Ignore files and folders】 一栏添加 .idea;.iml;

image

8、设置默认浏览器

File --> Tools --> Web Browsers

image

9、Git配置

File --> Setting --> Version Control --> Git

image

10、自动导包

Settings --> Editor --> General --> Auto Import

image

11、鼠标悬浮提示

File --> Editor --> Code Completion

image

12、maven配置

File --> Settings --> Build,Execution,Deployment --> Build Tools --> Maven

image

File --> Settings --> Build,Execution,Deployment --> Build Tools --> Maven --> Runner

VM Options中添加:-DarchetypeCatalog=internal

image

13、自动编译(热部署)

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

image

14、多行显示文件标签

File --> Settings --> Editor --> Editor Tabs

image

15、修改注释风格

File --> Settings --> Editor --> Code Style --> Java --> Code Generation

image

16、给选中内容添加双引号

File --> Setting > Editor > General > Smart Keys

image

17、取消双击shift弹出全局搜索框

ctrl+shift+a --> 输入registry,回车

image

18、内存优化

IDEA默认启动配置主要考虑低配置的用户,参数设置的不高,导致启动慢运行也不流畅,这里我们需要优化下启动和运行配置。

找到idea的安装目录,找到bin文件夹里面的idea64.exe.vmoptions文件,打开编辑:

参数说明:

  • -Xms 是最小启动内存参数
  • -Xmx 是最大运行内存参数
  • -XX:ReservedCodeCacheSize 保留代码占用的内存容量参数

image

建议8G内存的改为:

-Xms512m
-Xmx1024m
-XX:ReservedCodeCacheSize=300m

16G内存的改为:

-Xms1024m
-Xmx2048m
-XX:ReservedCodeCacheSize=500m

19、类注释模板

File --> Settings --> Editor --> File and Code Templates --> Files --> Class

  • 类模板
/**
 *
 * @ClassName: ${NAME}
 * @Description: TODO
 * @Author ONESTAR
 * @Date: ${DATE} ${TIME}
 * @QQ群:530311074
 * @URL:https://onestar.newstar.net.cn/
 * @Version 1.0
 */
public class ${NAME} {
}

image

  • 效果图

image

20、方法注释模板

  1. 创建分组:File --> Settings --> Editor --> Live Templates

image

  1. 创建模板:选中刚刚创建的分组,点击右边的加号,选择Live Template,创建一个模板,如下:
    • Abbreviation:填模板的缩写,可以使用*号作为代号,方便后面调用模板。
    • Description:模板描述
    • Options→Expand with:填注释模板的扩展快捷键,根据使用习惯,这里使用默认的Tab,勾选下面选项。
    • Template text:填写注释模板的内容。参数名使用${参数名}$的格式。模板如下

image

方法注释模板:

**
 * @description TODO
 * @author $user$
 * @date $year$$month$$date$ $time$
 $param$
 * @throws $return$
 */
  1. 点击模板页面最下方的警告define,来设置将模板应用于哪些场景,选择Everywhere-->Java即可,再点击Edit variables,会读取刚刚在注释模板中的配置的参数${参数名}$。

image

  1. 在Expression的下拉框中选择方法为其赋值

image

param和return填入如下:

param:

groovyScript("def result=''; def params=\"${_1}\".replaceAll('[\\\\[|\\\\]|\\\\s]', '').split(',').toList(); for(i = 0; i < params.size(); i++) {result+=' * @param ' + params[i] + ((i < params.size() - 1) ? '\\n' : '')}; return result", methodParameters())

return:

groovyScript("def returnType = \"${_1}\"; def result ='';if(returnType=='null'||returnType=='void'){return;}else{result += '\\n * @return ' + returnType; return result;}", methodReturnType()); 
  1. 效果图,在方法上面输入【/*】,然后按【TAB】键即可

image

  • 作者:管理员(联系作者)
  • 发表时间:2022-01-08 18:04
  • 版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)
  • 公众号转载:请在文末添加作者公众号二维码
  • 评论