Snippets插件--代码模板

VScode使用的代码模板

参考

搞懂怎么制作代码模板,提高编程效率

VScode 中 Snippets插件的代码模板

"prefix"可以同名,但要写"description"来区分

C语言

"c_main": {
		"prefix": "c",
		"body": [
			"#include",
			"",
			"",
			"int main()",
			"{",
			"",
			"\treturn 0;",
			"}"			
		],
		"description": "c_main"
	},

C++

"C++_main": {
		"prefix": "c++",
		"body": [
			"#include",
			"using namespace std; ",
			"",
			"",
			"int main(int argc, char * argv[])",
			"{",
			"",
			"\treturn 0;",
			"}"
			
		],
		"description": "C++_main"
	},

ros2

"ros2_main": {
		"prefix": "ros2_node_cpp",
		"body": [
			"#include \"rclcpp/rclcpp.hpp\"",
			" "," ",
			"// 3.定义节点类;",
			"class ${1:Mynode} : public rclcpp::Node",
			"{",
			"public:",
			"\t${1:Mynode}(): Node(\"${1:mynode}_node_cpp\"){",			
			" ",
			"\t}",
			" ",
			"private:",
			" ",
			"};",
			" ",
			"int main(int argc, char * argv[])",
			"{",
			"\t// 2.初始化 ROS2 客户端;",
			"\trclcpp::init(argc, argv);",
			"\t// 4.调用spin函数,并传入节点对象指针。",
			"\trclcpp::spin(std::make_shared<${1:Mynode}>());",
			"\t// 5.释放资源;",
			"\trclcpp::shutdown();",
			"\treturn 0;",
			"}",
			" "
		],
		"description": "my ros2_cpp example"
	}

未完待续…

你可能感兴趣的:(vscode,插件,Snippets)