{"id":260443,"date":"2024-05-15T13:34:37","date_gmt":"2024-05-15T05:34:37","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/260443.html"},"modified":"2024-05-15T13:34:42","modified_gmt":"2024-05-15T05:34:42","slug":"vscode-%e7%94%a8%e6%88%b7%e8%87%aa%e5%ae%9a%e4%b9%89%e4%bb%a3%e7%a0%81%e7%89%87%e6%ae%b5%ef%bc%9a%e5%a6%82%e4%bd%95%e8%8e%b7%e5%8f%96%e8%af%a5%e6%96%87%e4%bb%b6%e5%90%8d-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/260443.html","title":{"rendered":"vscode \u7528\u6237\u81ea\u5b9a\u4e49\u4ee3\u7801\u7247\u6bb5\uff1a\u5982\u4f55\u83b7\u53d6\u8be5\u6587\u4ef6\u540d"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/27112345\/56f67559-d2c1-4d87-98e9-e141a17c4805.webp\" alt=\"vscode \u7528\u6237\u81ea\u5b9a\u4e49\u4ee3\u7801\u7247\u6bb5\uff1a\u5982\u4f55\u83b7\u53d6\u8be5\u6587\u4ef6\u540d\" \/><\/p>\n<p><p>\u81ea\u5b9a\u4e49\u4ee3\u7801\u7247\u6bb5\u5728Visual Studio Code (VS Code) \u4e2d\u662f\u4e00\u9879\u5f3a\u5927\u7684\u529f\u80fd\uff0c\u5b83\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u7f16\u7801\u6548\u7387\u3002<strong>\u8981\u83b7\u53d6\u5f53\u524d\u6587\u4ef6\u7684\u6587\u4ef6\u540d<\/strong>\uff0c\u4f60\u53ef\u4ee5\u5728\u7528\u6237\u4ee3\u7801\u7247\u6bb5\u4e2d\u4f7f\u7528\u7279\u5b9a\u7684\u53d8\u91cf\u3002\u8fd9\u4e9b\u53d8\u91cf\u7531VS Code\u63d0\u4f9b\uff0c\u80fd\u591f\u52a8\u6001\u63d2\u5165\u6587\u4ef6\u5c5e\u6027\u5982\u6587\u4ef6\u540d\u3001\u6587\u4ef6\u8def\u5f84\u7b49\u3002\u8981\u83b7\u5f97\u5f53\u524d\u6587\u4ef6\u7684\u6587\u4ef6\u540d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>$TM_FILENAME<\/code>\u8fd9\u4e2a\u9884\u5b9a\u4e49\u7684\u53d8\u91cf\u3002\u4f8b\u5982\uff0c\u5f53\u4f60\u9700\u8981\u5728\u4ee3\u7801\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u6ce8\u91ca\uff0c\u6807\u6ce8\u5f53\u524d\u7684\u6587\u4ef6\u540d\u65f6\uff0c\u5c31\u53ef\u4ee5\u5229\u7528\u8fd9\u4e2a\u53d8\u91cf\u6765\u81ea\u52a8\u63d2\u5165\u6587\u4ef6\u540d\u3002<\/p>\n<\/p>\n<p><p><strong>\u6269\u5c55\u5c55\u793a<\/strong>\uff1a<\/p>\n<\/p>\n<p><p><code>$TM_FILENAME<\/code>\u662f\u4e00\u4e2a\u7cfb\u7edf\u53d8\u91cf\uff0c\u4e0d\u9700\u8981\u7528\u6237\u8fdb\u884c\u4efb\u4f55\u989d\u5916\u5b9a\u4e49\uff0cVS Code\u4f1a\u5728\u6267\u884c\u4ee3\u7801\u7247\u6bb5\u65f6\u81ea\u52a8\u66ff\u6362\u8fd9\u4e2a\u53d8\u91cf\u4e3a\u5f53\u524d\u6587\u4ef6\u7684\u6587\u4ef6\u540d\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u6b63\u5728\u7f16\u8f91\u7684\u6587\u4ef6\u540d\u662f<code>example.js<\/code>\uff0c\u4f7f\u7528<code>$TM_FILENAME<\/code>\u5728\u63d2\u5165\u7684\u4ee3\u7801\u7247\u6bb5\u4e2d\u5c06\u4f1a\u81ea\u52a8\u88ab\u66ff\u6362\u6210<code>example.js<\/code>\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u521b\u5efa\u7528\u6237\u81ea\u5b9a\u4e49\u4ee3\u7801\u7247\u6bb5<\/h3>\n<\/p>\n<p><p>\u8981\u521b\u5efa\u7528\u6237\u81ea\u5b9a\u4e49\u4ee3\u7801\u7247\u6bb5\uff0c\u4f60\u9700\u8981\u5148\u8bbf\u95eeVS Code\u7684\u547d\u4ee4\u9762\u677f\u5e76\u9009\u62e9\u6216\u521b\u5efa\u4e00\u4e2a\u4ee3\u7801\u7247\u6bb5\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u6253\u5f00\u547d\u4ee4\u9762\u677f(Ctrl+Shift+P on Windows, Command+Shift+P on macOS)\u3002<\/li>\n<li>\u8f93\u5165&quot;configure user snippets&quot;\u5e76\u9009\u62e9\u5b83\u3002<\/li>\n<li>\u9009\u62e9\u76f8\u5e94\u7684\u8bed\u8a00\uff0c\u4f8b\u5982JavaScript\uff0c\u5219\u9009\u62e9&quot;JavaScript&quot;\u3002<\/li>\n<\/ol>\n<p><p>\u4f60\u5c06\u88ab\u5f15\u5bfc\u521b\u5efa\u6216\u4fee\u6539\u4e00\u4e2a<code>.json<\/code>\u6587\u4ef6\uff0c\u8fd9\u91cc\u4f60\u53ef\u4ee5\u6dfb\u52a0\u6216\u7f16\u8f91\u81ea\u5b9a\u4e49\u7684\u4ee3\u7801\u7247\u6bb5\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u6dfb\u52a0\u4ee3\u7801\u7247\u6bb5<\/h3>\n<\/p>\n<p><p>\u5728\u6253\u5f00\u7684\u4ee3\u7801\u7247\u6bb5\u6587\u4ef6\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5b9a\u4e49\u4e00\u4e2a\u65b0\u7684\u4ee3\u7801\u7247\u6bb5\uff0c\u4f7f\u7528<code>$TM_FILENAME<\/code>\u53d8\u91cf\u6765\u83b7\u53d6\u6587\u4ef6\u540d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-json\">{<\/p>\n<p>    &quot;Print to console&quot;: {<\/p>\n<p>        &quot;prefix&quot;: &quot;logfilename&quot;,<\/p>\n<p>        &quot;body&quot;: [<\/p>\n<p>            &quot;\/\/ Current File: $TM_FILENAME&quot;,<\/p>\n<p>            &quot;console.log(&#039;Current File: $TM_FILENAME&#039;);&quot;<\/p>\n<p>        ],<\/p>\n<p>        &quot;description&quot;: &quot;Log the current file name&quot;<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528\u81ea\u5b9a\u4e49\u4ee3\u7801\u7247\u6bb5<\/h3>\n<\/p>\n<p><p>\u521b\u5efa\u5b8c\u4ee3\u7801\u7247\u6bb5\u4e4b\u540e\uff0c\u8981\u4f7f\u7528\u5b83\uff0c\u53ea\u9700\u5728\u7f16\u8f91\u5668\u4e2d\u8f93\u5165\u5176\u524d\u7f00\uff08\u5728\u672c\u4f8b\u4e2d\u4e3a&quot;logfilename&quot;\uff09\uff0c\u7136\u540e\u4ece\u81ea\u52a8\u8865\u5168\u5efa\u8bae\u4e2d\u9009\u4e2d\u5b83\u3002\u4f60\u5c06\u770b\u5230\u524d\u7f00\u8865\u5168\u6210\u4e86\u8bbe\u7f6e\u597d\u7684\u7247\u6bb5\u6a21\u677f\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u5176\u4ed6\u53ef\u7528\u53d8\u91cf<\/h3>\n<\/p>\n<p><p>\u9664\u4e86<code>$TM_FILENAME<\/code>\uff0cVS Code\u8fd8\u63d0\u4f9b\u4e86\u5176\u4ed6\u7cfb\u7edf\u53d8\u91cf\u4f9b\u4ee3\u7801\u7247\u6bb5\u4f7f\u7528\uff1a<\/p>\n<\/p>\n<ul>\n<li><code>$TM_DIRECTORY<\/code>\uff1a\u5f53\u524d\u6587\u4ef6\u7684\u76ee\u5f55\u3002<\/li>\n<li><code>$TM_FILEPATH<\/code>\uff1a\u5f53\u524d\u6587\u4ef6\u7684\u5b8c\u6574\u8def\u5f84\u3002<\/li>\n<li><code>$CURRENT_YEAR<\/code>\u3001<code>$CURRENT_MONTH<\/code>\u3001<code>$CURRENT_DATE<\/code>\uff1a\u5f53\u524d\u7684\u5e74\u3001\u6708\u3001\u65e5\u3002<\/li>\n<\/ul>\n<p><p>\u8fd9\u4e9b\u53d8\u91cf\u53ef\u4ee5\u4e0e<code>$TM_FILENAME<\/code>\u4e00\u8d77\u4f7f\u7528\uff0c\u63d0\u4f9b\u66f4\u591a\u5173\u4e8e\u6587\u4ef6\u7684\u52a8\u6001\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u5b9e\u9645\u5e94\u7528\u793a\u4f8b<\/h3>\n<\/p>\n<p><p><strong>\u4f7f\u7528\u573a\u666f<\/strong>\uff1a<\/p>\n<\/p>\n<p><p>\u5047\u8bbe\u4f60\u7ecf\u5e38\u9700\u8981\u5728\u591a\u4e2a\u6587\u4ef6\u4e2d\u63d2\u5165\u4e00\u4e2a\u6807\u51c6\u7684\u7248\u6743\u58f0\u660e\uff0c\u8fd9\u4e9b\u6587\u4ef6\u53ef\u80fd\u662f<code>.js<\/code>\u6587\u4ef6\u6216<code>.css<\/code>\u6587\u4ef6\uff0c\u4f60\u5e0c\u671b\u7248\u6743\u58f0\u660e\u4e2d\u5305\u542b\u5f53\u524d\u6587\u4ef6\u7684\u540d\u79f0\u3002<\/p>\n<\/p>\n<p><p>\u53ef\u4ee5\u5b9a\u4e49\u4ee5\u4e0b\u4ee3\u7801\u7247\u6bb5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-json\">{<\/p>\n<p>    &quot;Copyright notice&quot;: {<\/p>\n<p>        &quot;prefix&quot;: &quot;copyright&quot;,<\/p>\n<p>        &quot;body&quot;: [<\/p>\n<p>            &quot;\/*&quot;,<\/p>\n<p>            &quot; * Copyright (c) ${CURRENT_YEAR} Your Company&quot;,<\/p>\n<p>            &quot; * File: $TM_FILENAME&quot;,<\/p>\n<p>            &quot; *&quot;,<\/p>\n<p>            &quot; * All rights reserved.&quot;,<\/p>\n<p>            &quot; *\/&quot;<\/p>\n<p>        ],<\/p>\n<p>        &quot;description&quot;: &quot;Add a copyright notice with the file name&quot;<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5f53\u4f60\u5728\u4efb\u4f55<code>.js<\/code>\u6216<code>.css<\/code>\u6587\u4ef6\u4e2d\u952e\u5165<code>copyright<\/code>\u5e76\u9009\u62e9\u8fd9\u4e2a\u4ee3\u7801\u7247\u6bb5\u65f6\uff0c\u5b83\u5c06\u81ea\u52a8\u63d2\u5165\u7248\u6743\u58f0\u660e\uff0c\u5e76\u628a<code>$TM_FILENAME<\/code>\u66ff\u6362\u6210\u5f53\u524d\u7f16\u8f91\u7684\u6587\u4ef6\u540d\u3002<\/p>\n<\/p>\n<p><p>\u7efc\u4e0a\uff0c\u901a\u8fc7\u8fd0\u7528<code>$TM_FILENAME<\/code>\u8fd9\u4e00\u7cfb\u7edf\u53d8\u91cf\uff0c\u4f60\u53ef\u4ee5\u5728VS Code\u4e2d\u521b\u5efa\u80fd\u591f\u81ea\u52a8\u83b7\u53d6\u5e76\u4f7f\u7528\u5f53\u524d\u6587\u4ef6\u540d\u7684\u9ad8\u6548\u4ee3\u7801\u7247\u6bb5\uff0c\u6781\u5927\u5730\u63d0\u5347\u7f16\u7a0b\u5de5\u4f5c\u6548\u7387\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>1. \u5982\u4f55\u5728VSCode\u4e2d\u83b7\u53d6\u5f53\u524d\u6587\u4ef6\u7684\u6587\u4ef6\u540d\uff1f<\/strong><\/p>\n<p>\u5728VSCode\u4e2d\uff0c\u8981\u83b7\u53d6\u5f53\u524d\u6587\u4ef6\u7684\u6587\u4ef6\u540d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528VSCode\u5185\u7f6e\u7684\u5feb\u6377\u952e\uff1a\u6309\u4e0b<code>Ctrl + Shift + P<\/code>\uff0c\u7136\u540e\u8f93\u5165<code>Copy Absolute Path<\/code>\uff0c\u6309\u4e0b\u56de\u8f66\u3002\u8fd9\u5c06\u628a\u5f53\u524d\u6587\u4ef6\u7684\u5b8c\u6574\u8def\u5f84\u590d\u5236\u5230\u526a\u8d34\u677f\u4e2d\u3002\u4f60\u53ef\u4ee5\u4ece\u4e2d\u63d0\u53d6\u6587\u4ef6\u540d\u3002<\/li>\n<li>\u4f7f\u7528VSCode\u7684\u5185\u7f6e\u53d8\u91cf\uff1a\u4f60\u53ef\u4ee5\u5728\u81ea\u5b9a\u4e49\u4ee3\u7801\u7247\u6bb5\u4e2d\u4f7f\u7528<code>${TM_FILENAME}<\/code>\u53d8\u91cf\u6765\u83b7\u53d6\u5f53\u524d\u6587\u4ef6\u7684\u6587\u4ef6\u540d\u3002\u5728\u4ee3\u7801\u7247\u6bb5\u4e2d\u4f7f\u7528<code>${TM_FILENAME}<\/code>\u5c06\u81ea\u52a8\u63d2\u5165\u5f53\u524d\u6587\u4ef6\u7684\u6587\u4ef6\u540d\u3002<\/li>\n<\/ul>\n<p><strong>2. \u5982\u4f55\u5728VSCode\u7684\u81ea\u5b9a\u4e49\u4ee3\u7801\u7247\u6bb5\u4e2d\u83b7\u53d6\u5f53\u524d\u6587\u4ef6\u7684\u6587\u4ef6\u540d\uff1f<\/strong><\/p>\n<p>\u5728VSCode\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5728\u81ea\u5b9a\u4e49\u4ee3\u7801\u7247\u6bb5\u4e2d\u901a\u8fc7<code>${TM_FILENAME_BASE}<\/code>\u53d8\u91cf\u6765\u83b7\u53d6\u5f53\u524d\u6587\u4ef6\u7684\u6587\u4ef6\u540d\uff08\u4e0d\u5305\u62ec\u6269\u5c55\u540d\uff09\u3002\u4ee5\u4e0b\u662f\u83b7\u53d6\u5f53\u524d\u6587\u4ef6\u540d\u7684\u793a\u4f8b\u4ee3\u7801\u7247\u6bb5\uff1a<\/p>\n<pre><code>&quot;Print Filename&quot;: {\n    &quot;prefix&quot;: &quot;pf&quot;,\n    &quot;body&quot;: [\n        &quot;console.log(&#039;Current filename: ${TM_FILENAME_BASE}&#039;);&quot;\n    ],\n    &quot;description&quot;: &quot;Prints the current filename&quot;\n}\n<\/code><\/pre>\n<p>\u5728\u4ee3\u7801\u7247\u6bb5\u4e2d\uff0c<code>${TM_FILENAME_BASE}<\/code>\u5c06\u88ab\u66ff\u6362\u4e3a\u5f53\u524d\u6587\u4ef6\u7684\u6587\u4ef6\u540d\u3002<\/p>\n<p><strong>3. \u5982\u4f55\u5728VSCode\u7684\u81ea\u5b9a\u4e49\u4ee3\u7801\u7247\u6bb5\u4e2d\u83b7\u53d6\u5f53\u524d\u6587\u4ef6\u7684\u5b8c\u6574\u8def\u5f84\uff1f<\/strong><\/p>\n<p>\u5728VSCode\u4e2d\uff0c\u5982\u679c\u4f60\u60f3\u8981\u83b7\u53d6\u5f53\u524d\u6587\u4ef6\u7684\u5b8c\u6574\u8def\u5f84\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>${file}<\/code>\u53d8\u91cf\u3002\u4ee5\u4e0b\u662f\u83b7\u53d6\u5f53\u524d\u6587\u4ef6\u5b8c\u6574\u8def\u5f84\u7684\u793a\u4f8b\u4ee3\u7801\u7247\u6bb5\uff1a<\/p>\n<pre><code>&quot;Print File Path&quot;: {\n    &quot;prefix&quot;: &quot;pfp&quot;,\n    &quot;body&quot;: [\n        &quot;console.log(&#039;Current file path: ${file}&#039;);&quot;\n    ],\n    &quot;description&quot;: &quot;Prints the current file path&quot;\n}\n<\/code><\/pre>\n<p>\u5728\u4ee3\u7801\u7247\u6bb5\u4e2d\uff0c<code>${file}<\/code>\u5c06\u88ab\u66ff\u6362\u4e3a\u5f53\u524d\u6587\u4ef6\u7684\u5b8c\u6574\u8def\u5f84\u3002\u4f60\u53ef\u4ee5\u6839\u636e\u9700\u8981\u8fdb\u884c\u8fdb\u4e00\u6b65\u7684\u5904\u7406\u548c\u63d0\u53d6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u81ea\u5b9a\u4e49\u4ee3\u7801\u7247\u6bb5\u5728Visual Studio Code (VS Code) \u4e2d\u662f\u4e00\u9879\u5f3a\u5927\u7684\u529f\u80fd\uff0c\u5b83\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u7f16 [&hellip;]","protected":false},"author":3,"featured_media":260450,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/260443"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=260443"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/260443\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/260450"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=260443"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=260443"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=260443"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}