sublime text 3 ,React,html元素自动补全方法(用Emmet写法写jsx中的html)

1. 安装emmet: Preferences -> Package Control -> Install Package -> emmethtml

2. 配置emmet: Preferences -> Package Settings -> Emmet -> Key Bindings - Userthis

 将下方的代码贴到打开的文件中,而后就可使用tab键对render中的(部分)html元素使用自动补全功能了spa

 1 [  2  {  3         "keys": [  4             "super+e"
 5  ],  6         "args": {  7             "action": "expand_abbreviation"
 8  },  9         "command": "run_emmet_action", 10         "context": [ 11  { 12                 "key": "emmet_action_enabled.expand_abbreviation"
13  } 14  ] 15  }, 16  { 17         "keys": [ 18             "tab"
19  ], 20         "command": "expand_abbreviation_by_tab", 21         "context": [ 22  { 23                 "operand": "source.js", 24                 "operator": "equal", 25                 "match_all": true, 26                 "key": "selector"
27  }, 28  { 29                 "key": "preceding_text", 30                 "operator": "regex_contains", 31                 "operand": "(\\b(a\\b|div|span|p\\b|button)(\\.\\w*|>\\w*)?([^}]*?}$)?)", 32                 "match_all": true
33  }, 34  { 35                 "key": "selection_empty", 36                 "operator": "equal", 37                 "operand": true, 38                 "match_all": true
39  } 40  ] 41  } 42 ]

  补充:code

  在贴了上述代码以后,只有部分标签用tab键可以自动补全,可是还有不少标签只能用ctrl+e补全,好比h1,Route等,经查阅,将上述代码替换为下面的代码,则能解决这个问题htm

 1 [{  2     "keys": ["tab"],  3     "command": "expand_abbreviation_by_tab",  4 
 5     // put comma-separated syntax selectors for which 
 6     // you want to expandEmmet abbreviations into "operand" key 
 7     // instead of SCOPE_SELECTOR.
 8     // Examples: source.js, text.html - source
 9     "context": [{ 10             "operand": "source.js", 11             "operator": "equal", 12             "match_all": true, 13             "key": "selector"
14  }, 15 
16         // run only if there's no selected text
17  { 18             "match_all": true, 19             "key": "selection_empty"
20  }, 21 
22         // don't work if there are active tabstops
23  { 24             "operator": "equal", 25             "operand": false, 26             "match_all": true, 27             "key": "has_next_field"
28  }, 29 
30         // don't work if completion popup is visible and you
31         // want to insert completion with Tab. If you want to
32         // expand Emmet with Tab even if popup is visible -- 
33         // remove this section
34  { 35             "operand": false, 36             "operator": "equal", 37             "match_all": true, 38             "key": "auto_complete_visible"
39  }, { 40             "match_all": true, 41             "key": "is_abbreviation"
42  } 43  ] 44 }]
相关文章
相关标签/搜索