Visual Studio Code修改HTML Snippets外掛程式中預設範本內容__HTML

來源:互聯網
上載者:User

最近在熟悉用VSC做前端開發編輯器,發現snippets這個功能很好用,就是自動幫你輸入HTML標籤,安裝HTML Snippets外掛程式(0.1.0)後,直接在代碼裡面輸入html5然後敲斷行符號就會自動幫你把一個HTML5標準標籤模板給填充好,但是有一個小問題就是,自動填滿的效果是這樣的:

<!DOCTYPE html><html lang="en">    <head>        <title></title>        <meta charset="UTF-8">        <meta name="viewport" content="width=device-width, initial-scale=1">        <link href="css/style.css" rel="stylesheet">    </head>    <body>    </body></html>

這裡lang=”en”,我想修改預設填充成lang=”zh-CN”,小折騰了一下,找到了這個外掛程式的設定檔位於

C:\Users\Dexter\.vscode\extensions\abusaidm.html-snippets-0.1.0\snippets\snippets.json

開啟這個檔案,找到定義html5映射的部分,修改如下,重啟一下VSC,再輸入html5就變成想要的效果了

"html5": {    "prefix": "html5",    "body": [        "<!DOCTYPE html>",        "<html lang=\"$1zh-CN\">",            ~~這裡原來是en~~        "\t<head>",        "\t\t<title>$2</title>",        "\t\t<meta charset=\"UTF-8\">",        "\t\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">",        "\t\t<link href=\"$3css/style.css\" rel=\"stylesheet\">",        "\t</head>",        "\t<body>",        "\t$4",        "\t</body>",        "</html>"        ],    "description": "HTML - Defines a template for a html5 document",    "scope": "text.html"    },
補充一下

也可以在檔案-喜好設定-使用者自訂程式碼片段,找到HTML後,在html.json設定檔裡面寫上自己常用的程式碼片段,例如下面這個是我修改的包含Vue.js引用的HTML5代碼模板:

{    /*    // Place your snippets for HTML here. Each snippet is defined under a snippet name and has a prefix, body and     // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:    // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the     // same ids are connected.    // Example:    "Print to console": {        "prefix": "log",        "body": [            "console.log('$1');",            "$2"        ],        "description": "Log output to console"    }*/    "Vue": {        "prefix": "vue",        "body": [            "<!DOCTYPE html>",            "<html lang=\"zh-CN\">",            "\t<head>",            "\t\t<title>$1</title>",            "\t\t<meta charset=\"UTF-8\">",            "\t\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">",            "\t\t<script src=\"https://cdn.bootcss.com/vue/2.2.2/vue.min.js\"></script>",            "\t</head>",            "\t<body>",            "\t$2",            "\t</body>",            "</html>"        ],        "description": "vue - Defines a template for a vue & html5 document"    }}
這裡需要注意一下,代碼中$1,$2標註的位置是自動插入程式碼片段之後游標的位置,$1是預設位置,$2是按tab鍵之後會跳轉到的下一個位置
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.