IDEA2023 custom Live Template and unified settings annotation

Table of contents

1. Highly reusable code blocks

2. Customize Live Template

3. Set annotation information


1. Highly reusable code blocks

        During the development process, there are often code snippets that need to be reused. In order to facilitate quick copying and pasting, you can use IDEA's lIve Template to save these code snippets, and you can customize keywords. When using it, you only need to enter the keyword and press the "Enter" key to directly output the code block.

For example, enter "psvm" "Enter" key (or press 'Tab' key) in IDEA, maln will be generated quickly 

IDEA provides the following lIve Template by default:
sout: can quickly generate "System.out.printlnO"
soutm can quickly output the current class and method name "System. out. printl n (helio. helio)"
psfs can quickly output "publicC static final String"
fon can quickly output "for (int i = 0; , < ; i++) {}"
ifn: You can quickly output "if (args == nuli) {}" or enter ".notnull" after completing parameter input and press the "Enter" key.

2. Customize Live Template

        If the default Live Template does not meet your needs, you can use a custom Live Template:
①. Select the "File Settings" command (or "Ctrl + Alt + S' ) in the IDEA menu bar.
②. Select "Edltor--Live Template", then click the "+" sign, and you can customize the code block in the pop-up window.
        Abbreviation represents adding abbreviation statements, such as psvm. Description represents description information for later reference.
Template text represents the code to be copied.

3. Set annotation information

        During the development process, it is often necessary to set annotation information. IDEA provides a "file and code template" template, which can be used in the new
Automatically add comments when building code. For example, the specific method of adding author annotation information is as follows:
①. Open IDEA. Select the "File Settings" command in the menu bar.
②. Click the "Editor" section button in the Settings window, and click the "file and code template" button in the pop-up window. Click the "includes" button on the right side of the window, and in the box on the right, enter the template that annotates the author information below.
/**
  * FileName: ${NAME}
  * Author: bai
  * Date:   ${YEAR}${DATE}${TIME}
  * Description:${DESCRIPTION}
  * History:
  * <author>      <time>     <version>     <desc>
  * 作者姓名       修改时间      版本号         描述
  */
After setting it up, the author information will appear when creating a new class in the future, as shown in the figure.

Guess you like

Origin blog.csdn.net/weixin_49171365/article/details/130461048