代码自动补全(live templates)
IDEA中代码自动补全
在IDEA中通过”快捷键+TAB”实现代码自动补全。
比如System.out.println(“”);,在IDEA中可以sout + TAB实现。
常用代码自动补全快捷键
快捷键 | 说明 |
---|---|
sout | System.out.println(“”); |
psvm | main方法 |
编写自己的live templates
1.打开Live Templates,点击+新建live template或live template分组,我这里新建了一个名为tag的live template在名为My Live Template的分组里。
2.IDEA提供了相关表达式可以实现某些操作,点击Edit variables编辑模板变量,在Expression中调用相关表达式。
比如,我在模板中定义了一个NAME模板变量($NAME$
),点击Edit variables就可以看到这个变量,在Expression中调用了className()返回当前类的类名。
live templates表达式参考文档地址:https://www.jetbrains.com/idea/help/creating-and-editing-template-variables.html
3.在live template上右键选择Change context可以定义该live templates可以在哪些语言中使用
4.使用自定义live template
常用设置项
常用快捷键
快捷键 | 说明 |
---|---|
Alt + Ctrl + S | 打开Settings |
Alt + Ctrl + Shift |