参考
搞懂怎么制作代码模板,提高编程效率
VScode 中 Snippets插件的代码模板
"prefix"可以同名,但要写"description"来区分
"c_main": {
"prefix": "c",
"body": [
"#include",
"",
"",
"int main()",
"{",
"",
"\treturn 0;",
"}"
],
"description": "c_main"
},
"C++_main": {
"prefix": "c++",
"body": [
"#include",
"using namespace std; ",
"",
"",
"int main(int argc, char * argv[])",
"{",
"",
"\treturn 0;",
"}"
],
"description": "C++_main"
},
"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"
}
未完待续…