Skip to content

Instantly share code, notes, and snippets.

@max-mykhailenko
Last active November 25, 2022 23:25
Show Gist options
  • Save max-mykhailenko/41d0c3991d92f38dcbc6 to your computer and use it in GitHub Desktop.
Save max-mykhailenko/41d0c3991d92f38dcbc6 to your computer and use it in GitHub Desktop.
Sublime text 3. Enable Emmet in JSX files with Sublime React plugin

This is no longer needed as Emmet supports JSX - you just need to turn it all on. Did a quick tutorial: http://wesbos.com/emmet-react-jsx-sublime/

Thanks, @wesbos

Problem

  • Using emmet in jsx files
  • Emmet expands text when js autocomplete needed
  • Using className instead of class

How it works

  • Install plugin RegReplace
  • Install plugin Chain Of Command
  • Merge files from this gist to your Packages/User directory

Emmet will expand

  • .someClass
  • a.someClass (list of tags look in Default (OSX).sublime-keymap, now it's a|div|span|p|button)
  • div>p
[
{
"keys": ["tab"],
"command": "chain",
"args": {
"commands": [
["expand_abbreviation_by_tab"],
["reg_replace", {"replacements": ["js_class"]}]
]
},
"context": [
{"operand": "source.js", "operator": "equal", "match_all": true, "key": "selector"},
{"key": "preceding_text", "operator": "regex_contains", "operand": "(\\w+>\\w+|\\s(\\.?|a|div|span|p|button)\\.\\w+)", "match_all": true},
{"key": "selection_empty", "operator": "equal", "operand": true, "match_all": true}
]
}
]
{
"replacements": {
"js_class": {
"find": " class=\"",
"replace": " className=\"",
"greedy": true,
"case": false
}
}
}
@maxlibin
Copy link

Thanks!!

@shenders13
Copy link

Thanks - ive been frustrated for months not having autocomplete on my JSX.

@speaud
Copy link

speaud commented Dec 2, 2017

It's been said but, again, thanks!

@williamsnieves
Copy link

great!!! thank you 👍

@jptcnde
Copy link

jptcnde commented Mar 4, 2018

this is awesome, just switch back from vscode to subl
thanks 🤘

@jt3k
Copy link

jt3k commented Apr 16, 2018

many years have passed and this is still actual.
Make the plugin!

@whck6
Copy link

whck6 commented Nov 15, 2018

it's work!

@stiofand
Copy link

stiofand commented Jan 15, 2019

I have folowed all this all the latest packages etc, but emmet expansion seems to be working ONLY by creating div elements. So typing .mydiv and pressing tab, gives me <div className="mydiv></div> as it should, however, any other element; for example,
h1.header tab does nothing at all. Not even pgets expanded. I'm really trying to avoid going back to VSCODE as Sublime is so fast, but this configuration is beginning to feel a little vimish

@artuska
Copy link

artuska commented Feb 26, 2019

Ctrl+E expands all kind of abbreviations in any kind of file.

@IoanFerezan
Copy link

Ctrl+E < this is what I needed, more than enough for me. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment