VS Code自动生成文件头

源码通常需要在文件头插入注释,提供作者、修改时间等信息。举个例子:

1
2
3
4
5
6
/*
 * Author: fasion
 * Created time: 2020-10-26 20:04:15
 * Last Modified by: fasion
 * Last Modified time: 2020-10-28 10:06:23
 */

如果每一个源码文件都需要自己维护文件头,那得多麻烦呀!

好在 VS Code 提供了一个很强大的插件—— psioniq File Header ,专门用来维护源码文件头!我们只需稍加配置,即可高枕无忧:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
{
    "psi-header.config": {
        "author": "fasion",
        "authorEmail": "fasionchan@gmail.com"
    },

    "psi-header.lang-config": [
        {
            "language": "shellscript",
            "begin": "",
            "prefix": "# ",
            "end": "",
            "beforeHeader": [
                "#!/bin/sh",
                "",
            ],
        },
        {
            "language": "python",
            "begin": "'''",
            "prefix": "",
            "end": "'''",
            "beforeHeader": [
                "#!/usr/bin/env python",
                "# -*- encoding=utf8 -*-",
                "",
            ],
        },
        {
            "language": "makefile",
            "begin": "",
            "prefix": "# ",
            "end": "",
        },
        {
            "language": "restructuredtext",
            "begin": "..",
            "prefix": "    ",
            "end": ""
        },
        {
            "language": "markdown",
            "begin": "---",
            "prefix": "",
            "end": "---",
            "modDate": "date:",
            "modDateFormat": "YYYY-MM-DD[T]HH:mm:ssZ"
        }
    ],

    "psi-header.changes-tracking": {
        "isActive": true,
        "modAuthor": "Last Modified by:",
        "modDate": "Last Modified time:",
        "modDateFormat": "YYYY-MM-DD HH:mm:ss"
    },

    "psi-header.templates": [
        {
            "language": "*",
            "template": [
                "Author: <<author>>",
                "Created time: <<filecreated('YYYY-MM-DD HH:mm:ss')>>",
                "Last Modified by:",
                "Last Modified time:",
            ]
        },
        {
            "language": "markdown",
            "template": [
                "author: <<author>>",
                "date:",
            ]
        },
    ]
}

小菜笔记】系列文章首发于公众号【小菜学编程】,敬请关注:

【小菜笔记】系列文章首发于公众号【小菜学编程】,敬请关注: