目录
- vscode 自定义代码模板
- Reference
vscode 自定义代码模板
-
select User snippets from Settings on the bottom left corner.
-
select a certain language
for example: cpp
- create your own snippets
格式如下,防着写
- 第一行"cpp template",模板的名称
- “prefix”,快捷键,在文件中输入cpp,按下tab就会自动填充"body"里的代码。
- ${CURRENT_YEAR} 这个是个变量,当年年份
- $1, $2,$3…是光标的顺序,按TAB键就可以切换为下一个,$0特殊 为光标最后所在地方。
- "description"代码片段描述,随便写写。
{"cpp template": {"prefix": "cpp","body": ["/** "," * @Date: ${CURRENT_YEAR} ${CURRENT_MONTH_NAME_SHORT} ${CURRENT_DATE}"," * @Time: ${CURRENT_HOUR}:${CURRENT_MINUTE}"," * @Author: Chris"," * @Desc: ${1:Input the description of this file}","**/""#include <iostream>","","using namespace std;","","int main() {"," $0"," return 0;","}",],"description": "A cpp file template."}
}
- Usage
输入cpp,然后按下tab
效果如图,光标先跳到desc 这里输入完文件描述,然后按下tab,光标就会跳到主函数里面
Reference
Snippets in Visual Studio Code