python配置
通过【文件→首选项→用户代码片段→选python】进入到 python.json修改的
python.json的具体内容如下:
{ "HEADER":{ "prefix": "qfr_header", "body": [ "#!/usr/bin/env python", "# -*- encoding: utf-8 -*-", "'''", "@File : $TM_FILENAME", "@Time : $CURRENT_YEAR/$CURRENT_MONTH/$CURRENT_DATE $CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND", "@Author : qfr ", "@Version : 1.0", "@Contact : qfr@whu.edu.cn", "@License : (C)Copyright 2021-2025, qfr&lz", "@Desc : None", "'''", "", "# here put the import lib", "$0" ], } }
使用的时候,输入:qfr_header即可。
C++配置
安装插件KoroFileHeader
在vscode左下角点击设置按钮,选择“设置”,然后输入“fileheader”,
- 文件头部注释:Fileheader:custom Made
- 函数注释:Fileheader:cursor Mode
随便点击哪个"在setting.json"中编辑,输入以下设置后保存,然后重启vscode更新设置
setting.json 内容如下:
{ "editor.suggestSelection": "first", "python.defaultInterpreterPath": "D:\\Anaconda3\\envs\\pytorch\\python.exe", "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue", "files.trimTrailingWhitespace": true "workbench.colorCustomizations": {undefined "editor.selectionHighlightBackground": "#288603", "editor.selectionBackground":"#288603", } // 文件头部注释 "fileheader.customMade": { "File" : "", "Date" : "Do not edit", "Author" : "qfr", "Version" : "1.0", "Contact" : "qfr@whu.edu.cn", "License" : "(C)Copyright 2021-2025, qfr&lz", "Desc" : "None" }, //函数注释 "fileheader.cursorMode": { "name" :"", "desc" :"", "param" :"", "return" :"" } }
文件头注释:
crtl+win+i(window)
函数注释:
crtl+win+t(window)
效果如下:
参考链接
VS Code 中配置新建 Python 文件自动添加头部注释
VS CODE 插件安装: