用户代码片段是Vscode中用户设置中的可自定义的部分,可以自己定义头文件和函数注释等等所有拟想要的东西:
- 头文件
- 函数注释
- 常用代码模块
在vscode中进入【用户代码片段】设置:
在弹出的命令框中选择python.json,打开后就会进入到python.json的编辑模式,看到下面这段代码:
Place your snippets for python here. Each snippet is defined under a snippet name and has a prefix, body and description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
$1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the same ids are connected.
那么就可以直接在下面编辑代码片段:
{ // Place your snippets for python here. Each snippet is defined under a snippet name and has a prefix, body and // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are: // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the // same ids are connected. // Example: "HEADER": { "prefix": "header", "body": [ "#!/usr/bin/env python", "# -*- encoding: utf-8 -*-", "'''", "@NAME :$TM_FILENAME", "@TIME :$CURRENT_YEAR/$CURRENT_MONTH/$CURRENT_DATE $CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND", "@AUTHOR :watalo", "@VERSION :0.0.x", "'''", "", "class CCC:", " def __init__(self):", " pass", "", "def Func():", " pass", "", "", "if __name__ == '__main__':" "$0" ], }, "FUNCTION":{ "prefix": "def", "body":[ "def func(var):", " '''", " @description:", " @param {var}:", " @return:", " '''", " pass", "$0", ] } }