场景:平时的开发中经常会写 main方法、private String ~、private static final String ~等有规律性的代码,这个时候如果能快速的生成这些模板的话就能大大加快开发速度,把重复性的工作分给intellij idea。

快速生成方法模板

快捷键 Ctrl+Alt+s进入如下:

intellij idea设置live template代码模板

intellij idea设置live template代码模板

新建Template Group后,我新建了个simons-defined组,然后选中后点击+号,新建Live Template
intellij idea设置live template代码模板
其中的1、2的值对应快捷代码和快捷提示,3对应的生成的方法体
intellij idea设置live template代码模板
接着要为自定义的模板选定适用的context,选中Java就好了
intellij idea设置live template代码模板

Apply应用OK即可,看下我的效果图:

intellij idea设置live template代码模板

注意,我这里的返回值和方法名是动态输入的,输完返回值,按enter键就自动跳到方法名的位置了,输完方法名再按enter键就直接跳到方法体中了。

快速生成private String ~模板

intellij idea设置live template代码模板

intellij idea设置live template代码模板

知道了 $VAR1$、$END$ 的具体含义,基本上就能灵活的配置任何你想要的代码了,类似的,你还可以配置方法注释模板、public static final int var=100这种常用的模板。

相关文章:

  • 2021-11-28
  • 2021-12-04
  • 2021-08-06
  • 2021-04-11
  • 2021-07-28
  • 2021-04-02
  • 2021-05-16
  • 2021-09-23
猜你喜欢
  • 2021-05-17
  • 2021-07-09
  • 2021-10-19
  • 2021-04-01
  • 2021-05-06
  • 2021-11-07
  • 2021-09-03
相关资源
相似解决方案