我偶然发现vscode可以创建用户代码片段
方法是File->Preferences->User Snippets
然后就是根据不同语言创建相应的代码片段了。
{ // Place your snippets for c 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: // "Print to console": { // "prefix": "log", // "body": [ // "console.log('$1');", // "$2" // ], // "description": "Log output to console" // } "main_template": { "prefix": "main", "body": [ "#include<stdio.h>", "#include<stdlib.h>", "int main()", "{", "return 0;", "}" ], "description": "main template" } }
注释说的很清楚了。
pre表示触发的字符串,body表示插入的代码。
上面这个是c语言的输入main就会弹出来。选中就会插入。
更多高级的特性需要看vscode的文档才能知道。