1

I would like to change the basic hmtl structure in VS code that is loaded with [! + tab] or [ctrl + space]

What I have when I press [! tab]:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>

What I would like to set it to for example :

<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">    
    <link rel='stylesheet' type='text/css' media='screen' href='main.css'>
    <title>Document</title>

</head>
<body>
    
</body>
</html>

I tried looking into the html snippets parameters but didn't find anything.

1

2 Answers 2

1

To overwrite existing emmets in VS Code:

  1. Create a snippets.json file, add this JSON structure and save it somewhere on your hard disk.

    {
      "html": {
       "snippets": {
         "!": "{<!DOCTYPE html>}+html[lang='fr']>(head>meta:utf+meta:vp+title{${2:Document}}+link[rel='stylesheet' type='text/css' media='screen' href='main.css'])+body"
       }
     },
     "css": {
       "snippets": {}
     }
    }
    
  2. Open the VS Code settings (Code → Preferences → Settings) and search for “Emmet Extensions Path”.
    Search for Emmet Extensions Path

  3. Click “Add Item”, enter the path to the folder where you’ve saved the snippets.json file you’ve created earlier, and press “OK”.
    add path of the folder

  4. Now try ! + TAB ;)


To learn more about how custom snippets work, check this article

Sign up to request clarification or add additional context in comments.

Comments

1

How to change the basic html structure in VS Code? (Emmet snippets)

  • Press html:5 + TAB or ! + TAB (TAB or ENTER)
  1. Go to "%userprofile%\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\emmet", you can use Windows + R

Screenshot of Visual Studio Code path "resources\app\extensions\emmet" de Visual Studio Code


  1. Open the file emmetNodeMain.js located in dist\node\emmetNodeMain.js
  • You should be seeing something like this; if the content appears truncated (as in this block quote), remember to enable word wrap with Alt + Z or from View > Toggle Word Wrap

(()=>{var e={7545:(e,t,n)=>{"use strict";n.r(t),n.d(t,{Token:()=>h,any...

//# sourceMappingURL=https://ticino.blob.core.windows.net/sourcemaps/5437...

Content of emmetNodeMain.js in Visual Studio Code


  1. Press CtrL + F to search within the file and type "{lang:" in the search box:

Result searching "{lang:" in emmetNodeMain.js

  • Replace lang:"en",locale:"en-US" with lang:"fr",locale:"fr", be careful not to accidentally delete "{" or ",")

Replacing html:5 languaje to French

  • Note: (French (Belgium) => fr-be, French (Canada) => fr-ca, French (Luxembourg) => fr-lu, French (Standard) => fr, French (Switzerland) => fr-ch).

  1. Now search for "+meta:vp":

Result of searching "+meta:vp" in emmetNodeMain.js

  • Replace "+meta:vp+title" with "+meta:vp+link[rel=stylesheet type=text/css media=screen href=main.css]+title", you can use Ctrl + H to achieve this.

  1. Close Visual Studio Code and reopen it.

  1. Verify that it works correctly by using HTML:5 + TAB or ! + TAB (You can use TAB or ENTER):

Modified Emmet snippet html:5

  • Preview of Emmet Abbreviation/snippet ! + TAB

Preview of Emmet Abbreviation html:5 or !


  • P. S.: I speak Spanish, which is why the screenshots appear like this, sorry.

1 Comment

Most likely those changes are overwritten when you update VSC

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.