{"id":1483,"date":"2023-11-05T20:56:25","date_gmt":"2023-11-05T12:56:25","guid":{"rendered":"https:\/\/lyvba.com\/?p=1483"},"modified":"2023-11-05T20:56:25","modified_gmt":"2023-11-05T12:56:25","slug":"vscode_snippets","status":"publish","type":"post","link":"https:\/\/lyvba.com\/index.php\/2023\/11\/05\/vscode_snippets\/","title":{"rendered":"VS Code \u521b\u5efa\u81ea\u5b9a\u4e49\u4ee3\u7801\u7247\u6bb5\uff0c\u4f7f\u7528\u7f29\u5199\u8bcd\u5feb\u901f\u63d2\u5165\u4ee3\u7801\u6a21\u7248"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2023\/07\/cpp.webp\" alt=\"\" \/><\/p>\n<h3>VSCode\u4e2d\u521b\u5efa\u81ea\u5b9a\u4e49\u7684\u4ee3\u7801\u7247\u6bb5\uff0c\u8bf7\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a<\/h3>\n<ul>\n<li>\n<p>\u6253\u5f00VSCode\uff0c\u5e76\u4f7f\u7528\u5feb\u6377\u952e <code>Ctrl + Shift + P<\/code>\u6253\u5f00\u547d\u4ee4\u9762\u677f\u3002<\/p>\n<\/li>\n<li>\n<p>\u5728\u547d\u4ee4\u9762\u677f\u4e2d\uff0c\u8f93\u5165 <code>snippets<\/code> \u5e76\u9009\u62e9 <code>Preferences: Configure User Snippets<\/code>\uff08\u9996\u6b21\u4f7f\u7528\u65f6\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u9009\u62e9\u8bed\u8a00\uff0c\u4f8b\u5982\u201cPreferences: Configure User Snippets for JavaScript\u201d\uff09\u3002<\/p>\n<\/li>\n<li>\n<p>\u8fd9\u5c06\u6253\u5f00\u4e00\u4e2a\u4ee5\u6240\u9009\u8bed\u8a00\u547d\u540d\u7684\u4ee3\u7801\u7247\u6bb5\u6587\u4ef6\u3002\u5982\u679c\u4f60\u60f3\u4e3a\u591a\u4e2a\u8bed\u8a00\u521b\u5efa\u4ee3\u7801\u7247\u6bb5\uff0c\u8bf7\u9009\u62e9 <code>New Global Snippets File<\/code>\uff08\u5168\u5c40\u4ee3\u7801\u7247\u6bb5\u6587\u4ef6\uff09\u3002<\/p>\n<\/li>\n<li>\n<p>\u5728\u4ee3\u7801\u7247\u6bb5\u6587\u4ef6\u4e2d\uff0c\u4f60\u5c06\u770b\u5230\u4e00\u4e2a\u7a7a\u7684JSON\u5bf9\u8c61\u3002\u8fd9\u662f\u7528\u4e8e\u5b9a\u4e49\u4ee3\u7801\u7247\u6bb5\u7684\u5730\u65b9\u3002<\/p>\n<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2023\/11\/Snippets.gif\" alt=\"\" \/><\/p>\n<h3>\u53c2\u8003\u56fe\u7247\u52a8\u753b\uff0c\u590d\u5236\u7c98\u8d34 <code>cpp.json<\/code> \u793a\u4f8b\u6a21\u7248\u6570\u636e<\/h3>\n<pre><code>{\n\/\/ C:\\Users\\vip\\AppData\\Roaming\\Code\\User\\snippets\n\/\/ $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. \n\n&quot;regex\u6a21\u7248&quot;: { &quot;prefix&quot;: &quot;regex&quot;,\n    &quot;body&quot;: [\n    &quot;#include &lt;bits\/stdc++.h&gt;\\nusing namespace std;\\nint main() {\\n  string s(\\&quot;A1234B5678C999 A1234B5678C999\\&quot;);&quot;\n    &quot;\\tsmatch m;  regex e(\\&quot;\\\\\\\\\\\\d+\\&quot;);\\n\\n  while (regex_search(s, m, e)) {\\n    cout &lt;&lt; m.str() &lt;&lt; endl;&quot;\n    &quot;\\t\\ts = m.suffix().str();\\n  }\\n}&quot;\n    ],  &quot;description&quot;: &quot;regex\u6a21\u7248&quot; },\n\n&quot;fopen\u793a\u4f8b\u6a21\u7248&quot;: { &quot;prefix&quot;: &quot;fopen&quot;,\n    &quot;body&quot;: [\n    &quot;#include &lt;stdio.h&gt;\\nint main() {\\n  FILE *pFile;\\n  pFile = fopen(\\&quot;myfile.txt\\&quot;, \\&quot;w\\&quot;);\\n  if (pFile != NULL) {&quot;,\n    &quot;    $1fputs(\\&quot;fopen example\\&quot;, pFile);\\n    fclose(pFile);\\n  }\\n  return 0;\\n}&quot;\n    ],  &quot;description&quot;: &quot;fopen\u793a\u4f8b\u6a21\u7248&quot; },\n\n&quot;printf\u6a21\u7248&quot;: { &quot;prefix&quot;: &quot;prf&quot;,\n    &quot;body&quot;: [\n    &quot;printf(\\&quot;%d\\&quot;, $1);&quot;\n    ],  &quot;description&quot;: &quot;printf\u6a21\u7248&quot; },\n\n&quot;C\u8bed\u8a00\u6a21\u7248&quot;: {    &quot;prefix&quot;: &quot;cc&quot;,\n    &quot;body&quot;: [\n    &quot;#include &lt;stdio.h&gt;\\n#include &lt;stdlib.h&gt;\\n&quot;,\n    &quot;int main()&quot;,\n    &quot;{&quot;,\n    &quot;\\t$1printf(\\&quot;Hello world!\\&quot;);&quot;,\n    &quot;\\treturn 0;&quot;,\n    &quot;}&quot;\n    ],  &quot;description&quot;: &quot;C\u8bed\u8a00\u6a21\u7248&quot; },\n\n&quot;CPP\u8bed\u8a00\u6a21\u7248&quot;: { &quot;prefix&quot;: &quot;cpp&quot;,\n    &quot;body&quot;: [\n    &quot;#include &lt;iostream&gt;\\n#include &lt;string&gt;\\n#include &lt;algorithm&gt;\\n&quot;,\n    &quot;using namespace std;&quot;,\n    &quot;int main(int argc, char* argv[])&quot;,\n    &quot;{&quot;,\n    &quot;\\t$1cout &lt;&lt; \\&quot;Hello world!\\&quot; &lt;&lt; endl;&quot;,\n    &quot;\\treturn 0;&quot;,\n    &quot;}&quot;   ],  &quot;description&quot;: &quot;CPP\u8bed\u8a00\u6a21\u7248&quot; }\n}<\/code><\/pre>\n<h3>\u4f7f\u7528 <code>snippets<\/code> \u7f29\u5199\u8bcd\u4ee3\u7801\u7247\u6bb5\u81ea\u52a8\u63d2\u5165\u4ee3\u7801\u6a21\u7248<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2023\/11\/cpp.gif\" alt=\"\" \/><\/p>\n<ul>\n<li>\u8f93\u5165 <code>cpp<\/code> \u540e\u7136\u540e\u6309\u4e0b\u56de\u8f66\u952e\uff0c\u5c31\u80fd\u63d2\u5165 cpp\u4ee3\u7801\u6a21\u7248<\/li>\n<li>\u8f93\u5165 <code>cc<\/code> \u80fd\u63d2\u5165 C\u8bed\u8a00\u4ee3\u7801\u6a21\u7248<\/li>\n<li>\u8f93\u5165 <code>regex<\/code> \u80fd\u63d2\u5165 regex\u4ee3\u7801\u6a21\u7248<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>VSCode\u4e2d\u521b\u5efa\u81ea\u5b9a\u4e49\u7684\u4ee3\u7801\u7247\u6bb5\uff0c\u8bf7\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a \u6253\u5f00VSCode\uff0c\u5e76\u4f7f\u7528\u5feb\u6377\u952e Ctrl  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1380,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[31,50],"class_list":["post-1483","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-learn","tag-cpp","tag-vscode"],"_links":{"self":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/1483","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/comments?post=1483"}],"version-history":[{"count":1,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/1483\/revisions"}],"predecessor-version":[{"id":1486,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/1483\/revisions\/1486"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/media\/1380"}],"wp:attachment":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/media?parent=1483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/categories?post=1483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/tags?post=1483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}