#CodeBeautification# VsCode adds author information and function comments with one click

need

If you want to write code that looks awesome at first glance, adding standardized comments is essential.

Standard and beautiful comments not only make the code look cool, but the most important thing is to improve the readability of the code. Whether you maintain it yourself or let others see it, it will improve efficiency.

For example, in the comments of C++ library functions, there is a long green comment at the beginning of each packaged library file, including the copyright of the file, function description, etc. When we write our own code, we must also develop the habit of adding comments to the code.

content

Generally, when writing each script file, a description of the file and author information must be written at the beginning of the file;

To write a function, you need to write the function, input and output, and pass parameters of the function.

This article records the method of adding comments in VsCode with one click.

specific method

1. Add user code snippet (click the gear in the lower left corner)

 2. Select the file type. Taking my commonly used C++ development as an example, the file type is cpp file. Here I select cpp.josn.

3. In cpp.josn, take author information and function comment code snippets as an example, add the following information to the file:

	"Print to Description": {
        "prefix": "description",
        "body": [
            "/*",
            "* @Description: $0",
            "* @Author: Chenxu Wen",
            "* @Date: $CURRENT_YEAR-$CURRENT_MONTH-$CURRENT_DATE",
            "* @LastEditTime: $CURRENT_YEAR-$CURRENT_MONTH-$CURRENT_DATE",
            "*/"
        ],
        "description": "a description mode"
    },
    "Print to func": {
        "prefix": "func",
        "body": [
            "/**",
            " * @func $1",
            " * @desc $2",
            " * @param {$3} $4 $5",
            " * @return {$6} $7",
            " */"
        ],
        "description": "a func mode"
    }

What follows "prefix" is the keyword, and what follows "body" is the body of the added comment.

4. Enter the keyword where you want to add a comment, and you can add the corresponding comment with one click.

 

 

Guess you like

Origin blog.csdn.net/qq_45461410/article/details/132364496