sublime text 3 ,React,html元素自動補全方法(用Emmet寫法寫jsx中的html)


1. 安裝emmet: Preferences -> Package Control -> Install Package -> emmet

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

 將下方的代碼貼到打開的文件中,然后就可以使用tab鍵對render中的(部分)html元素使用自動補全功能了

 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 ]

  補充:

  在貼了上述代碼之后,只有部分標簽用tab鍵能夠自動補全,但是還有很多標簽只能用ctrl+e補全,比如h1,Route等,經查閱,將上述代碼替換為下面的代碼,則能解決這個問題

 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 }]

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM