Vscode-ruby: Emmet isn't recognised in erb

Created on 13 Aug 2017  Â·  29Comments  Â·  Source: rubyide/vscode-ruby

Your environment

  • vscode-ruby version: 0.14.0
  • Ruby version: ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16
  • VS Code version: 1.15.0
  • Operating System: MacOS

Expected behavior

  1. Create a new file
  2. Set language mode to erb
  3. Type .myclass or any HTML like div, p etc
  4. Hit ctrl + space to list suggestions (if you don't have autosugesstion turned on)
  5. Expect to see emmet expanded abbreviations

Actual behavior

No suggestions returned

Steps to reproduce the problem

see Expected behavior


IIRC emmet used to work seamlessly with erb.
Perhaps its due to the change to emmet in vscode.
Workaround: set language mode to HTML.

feature-request

Most helpful comment

Add this to your settings:

"emmet.includeLanguages": {"erb": "html"}

All 29 comments

Add this to your settings:

"emmet.includeLanguages": {"erb": "html"}

Works like magic

You just need 2 steps to make it work: ( for VS code)

  1. "emmet.includeLanguages": {"erb": "html"} as mentioned by @coisnepe
  2. Install "erb
    Craig Maslowsk " extensions..... it helps erb syntax highlighting

@coisnepe Thanks!

You guys rock!

For anyone looking to add it for html.erb files, add this:

    "emmet.includeLanguages": {
      "html.erb": "html",
    },

@Zhao-Andy I tried
"emmet.includeLanguages": {
"html.erb": "html",
},

but this one doesn't work.
So I tried
"emmet.includeLanguages": {
"erb": "html",
},
this works perfectly...... Thanks

You can do this https://code.visualstudio.com/docs/languages/overview#_adding-a-file-extension-to-a-language. I need this for vscode recognize the coffe.erb extension as coffescript file

Would anyone mind writing up either a README entry for this stuff for something for the wiki?

"emmet.includeLanguages": {
"erb": "html",
}

I found that on my mac .html.erb are detected as .html.erb format instead of erb. You can find the format detection by opening your .html.erb file and see the bottom right section. Therefore @coisnepe solution doesn't work and @Zhao-Andy works and vice versa.

If you find your format detection as .html.erb and you wish to use @coisnepe solution, you may need to add these lines:

"files.associations": {
     "*.erb": "erb"
 }

Hope this helps.

Do you have additional extensions installed that would register an html.erb as a syntax? This extension doesn’t register that syntax name.

This is work for me!
"emmet.includeLanguages": {"erb": "html"}
tks! @coisnepe

In addition to "emmet.includeLanguages": {"erb": "html"} you need to install this extension :
https://marketplace.visualstudio.com/items?itemName=CraigMaslowski.erb

That extension is literally the same thing that's in this extension...the only difference is that it registers the .html.erb extension as ERB.

For anyone running that ERB extension, do you lose HTML highlighting and intellisense when the detected language is ERB?

Not sure why, but for me only worked this way
"emmet.includeLanguages": {"ruby": "html"}

I found that on my Mac .html.erb are detected as .html.erb format instead of erb.

Not sure why, but for me only worked this way “emmet.includeLanguages”: {“ruby”: “html”}

In case it helps future generations, the solution will depend on what language/format your ERB files are recognized as using. This comment (above) from @ariefrizkyr is helpful in this regard:

You can find the format detection by opening your .html.erb file and see the bottom right section.

For me (on a Mac), the default was Ruby but changed to erb after installing the Simple Ruby ERB extension. So keep any eye on what type of file VS Code thinks you have and configure accordingly.

Many thanks, @frogandcode. You just addressed the exact problem I was having. I had edited the config file and added "emmet.includeLanguages": {"erb":"html"}, but it wasn't working. Then I looked at the right lower corner of the editor and I saw that the language association for html.erb was "Plain text", and erb wasn't among the options to choose from. I installed Simple Ruby ERB and changed the language association to erb and now Emmet Abbreviation works perfectly in my html.erb files :)

Not sure why, but for me only worked this way
"emmet.includeLanguages": {"ruby": "html"}

I tried all of the options presented elsewhere in this thread, and this was what worked for me on Mac, running VS Code v 1.41.0 on a Mac running OS Catalina v 10.15.1

Add this to your settings:

"emmet.includeLanguages": {"erb": "html"}

Works like a charm

Works like magic

I don't understand, where exactly do you write "emmet.includeLanguages": ... ?

I don't understand, where exactly do you write "emmet.includeLanguages": ... ?

@Hassanelashram, that goes into VS Code settings file.

@raulrpearson thank you very much for taking the time to answer me, you were right, however i had a headache becasue i was trying it with "emmet.includeLanguages": {"erb": "html"}
but in reality i had to add: "emmet.includeLanguages": {"ruby": "html"}

thank you

So -- adding a file association { "*html.erb": "html" } enables snippets but disables erb highlighting and viceversa. A true Catch-22. Sucks.

For anyone looking to add it for html.erb files, add this:

    "emmet.includeLanguages": {
      "html.erb": "html",
    },

Thank you so much brother, your answer really helped, :)
High five.

@coisnepe
Thanks a lot your solution works fine.
Except there is a one little thing you should take care of :
It is Trigger Expansion on Tab
it need to be checked otherwise when you hit the tab the Emmet will not work fine.
To do that:

  • should go in Settings in Vscode
  • Then write Emmet in the search bar
  • By coming down a bit you will find this
    Screenshot from 2020-07-29 12-37-46
  • If its checked you are fine if not you need to check it.

@coisnepe
Thanks a lot your solution works fine.
Except there is a one little thing you should take care of :
It is Trigger Expansion on Tab
it need to be checked otherwise when you hit the tab the Emmet will not work fine.
To do that:

  • should go in Settings in Vscode
  • Then write Emmet in the search bar
  • By coming down a bit you will find this
    Screenshot from 2020-07-29 12-37-46
  • If its checked you are fine if not you need to check it.

Thanks. Exactly what I was looking for!

Not sure why, but for me only worked this way
"emmet.includeLanguages": {"ruby": "html"}

that's the one that did it for me, thanks a lot!

Was this page helpful?
0 / 5 - 0 ratings