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 }]
相關文章
相關標籤/搜索