将vscode打造成无敌的IDE添加自定义的snippet

Posted 奇妙之二进制

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将vscode打造成无敌的IDE添加自定义的snippet相关的知识,希望对你有一定的参考价值。

打开vscode 【文件】=》【首选项】=》【用户代码片段】,会让你输出代码片段类型,也就是给什么代码用的,
关于代码片段语法参考:

贴出我的C++代码片段:


	"for": 
		"prefix": "for",
		"body": [
			"for ($size_t $i = $1:0; $i < $2:length; $i++) ",
			"	$3",
			""
		],
		"description": "A Code snippet for 'for' loop"
	,
	"forr": 
		"prefix": "forr",
		"body": [
			"for (int $i = $1:length - 1; $i >= $2:0; $i--) ",
			"	$3",
			""
		],
		"description": "Code snippet for reverse 'for' loop"
	,
	"do": 
		"prefix": "do",
		"body": [
			"do ",
			"	$1",
			" while($2:condition);"
		],
		"description": "Code snippet for do...while loop"
	,
	"while": 
		"prefix": "while",
		"body": [
			"while ($1:condition) ",
			"	$2",
			""
		],
		"description": "Code snippet for while loop"
	,
	"foreach": 
		"prefix": "foreach",
		"body": [
			"for(auto& $var : $1:list) ",
			"	$2",
			""
		],
		"description": "Code snippet for const range-based for loop (c++11) statement"
	,
  "foreachconst": 
		"prefix": "foreachconst",
		"body": [
			"for(const auto& $var : $1:list) ",
			"	$2",
			""
		],
		"description": "Code snippet for const range-based for loop (c++11) statement"
	,
	"if": 
		"prefix": "if",
		"body": [
			"if ($1:condition) ",
			"	$2",
			""
		],
		"description": "Code snippet for if statement"
	,
	"else": 
		"prefix": "else",
		"body": [
			"else ",
			"	$1",
			""
		],
		"description": "Code snippet for else statement"
	,
	"else if": 
		"prefix": "else if",
		"body": [
			"else if ($1:condition) ",
			"	$2",
			""
		],
		"description": "Code snippet for else-if statement"
	,
	"enum": 
		"prefix": "enum",
		"body": [
			"enum $1:MyEnum ",
			"	$2",
			";"
		],
		"description": "Code snippet for enum"
	,
	"enum class": 
		"prefix": "enum class",
		"body": [
			"enum class $1:MyClass  $2 ;"
		],
		"description": "Code snippet for enum class (c++11)"
	,
	"class": 
		"prefix": "class",
		"body": [
			"class $1:MyClass ",
			" public:",
			"	$1();",
			"	$1($1 &&) = default;",
			"	$1(const $1 &) = default;",
			"	$1 &operator=($1 &&) = default;",
			"	$1 &operator=(const $1 &) = default;",
			"	~$1();",
			"",
			" private:",
			"	$2",
			";",
			"",
			"$1::$1() ",
			"",
			"",
			"$1::~$1() ",
			""
		],
		"description": "Code snippet for class"
	,
	"classi": 
		"prefix": "classi",
		"body": [
			"class $1:MyClass ",
			" public:",
			"	$1() = default;",
			"	$1($1 &&) = default;",
			"	$1(const $1 &) = default;",
			"	$1 &operator=($1 &&) = default;",
			"	$1 &operator=(const $1 &) = default;",
			"	~$1() = default;",
			"",
			" private:",
			"	$2",
			";"
		],
		"description": "Code snippet for class with inline constructor/destructor"
	,
	"namespace": 
		"prefix": "namespace",
		"body": [
			"namespace $1:MyNamespace ",
			"	$2",
			" // $1"
		],
		"description": "Code snippet for namespace"
	,
	"#ifdef": 
		"prefix": "#ifdef",
		"body": [
			"#ifdef $DEBUG",
			"$1",
			"#endif // $DEBUG"
		],
		"description": "Code snippet for #ifdef"
	,
	"#ifndef": 
		"prefix": "#ifndef",
		"body": [
			"#ifndef $1:1",
			"$2",
			"#endif // !$1"
		],
		"description": "Code snippet for #ifndef"
	,
	"#if": 
		"prefix": "#ifdef",
		"body": [
			"#ifdef $1:0",
			"$2",
			"#endif // $1"
		],
		"description": "Code snippet for #if"
	,
	"struct": 
		"prefix": "struct",
		"body": [
			"struct $1:MyStruct ",
			"	$2",
			";"
		],
		"description": "Code snippet for struct"
	,
	"switch": 
		"prefix": "switch",
		"body": [
			"switch ($1:switch_on) ",
			"	case $2:A:",
			"		$3",
			"		break;",
			"	default:",
			"		break;",
			""
		],
		"description": "Code snippet for switch statement"
	,
	"try": 
		"prefix": "try",
		"body": [
			"try ",
			"	$1",
			"",
			"catch (const std::exception&) ",
			"	$2",
			""
		],
		"description": "Code snippet for try catch"
	,
	"union": 
		"prefix": "union",
		"body": [
			"union $1:MyUnion ",
			"	$2",
			";"
		],
		"description": "Code snippet for union"
	,
	"cout": 
		"prefix": "cout",
		"body": [
			"std::cout << \\"$1:/* message */\\" << std::endl;"
		],
		"description": "Code snippet for printing to std::cout, provided the header is set"
	,
	"#inc": 
		"prefix": "#inc",
		"body": [
			"#include \\"$1\\""
		],
		"description": "Code snippet for #include \\" \\""
	,
	"#inc<": 
		"prefix": "#inc<",
		"body": [
			"#include <$1>"
		],
		"description": "Code snippet for #include < >"
	,
	"#def": 
		"prefix": "#def",
		"body": [
			"#define $1 ($2)"
			],
		"description": "Code snippet for #define ( )"
	,
	"main": 
		"prefix": "main",
		"body": [
			"int main(int argc, const char** argv) ",
				"	$1"
				"	return 0;",
			""
		],
		"description": "Code snippet for main function"
	

以上是关于将vscode打造成无敌的IDE添加自定义的snippet的主要内容,如果未能解决你的问题,请参考以下文章

将vscode打造无敌的IDE(14) tasks.json和launch.json配置详解,随心所欲添加自动化任务

将vscode打造成无敌的IDE安装一个自己满意的主题

将vscode打造成无敌的IDE安装一个自己满意的主题

将vscode打造成无敌的IDE开发神器vscode介绍

将vscode打造成无敌的IDE开发神器vscode介绍

将vscode打造成无敌的IDE打造shell IDE--三大神器