首页 文章

在Sublime中,Emmet自动完成不适用于php文件(扩展缩写)

提问于
浏览
0

我在Sublime中使用Emmet插件来处理HTML文件 . 但是当我想在像Laravel中的视图文件这样的PHP文件中键入HTML代码时,Emmet不会扩展缩写 .

例如:当我输入 html:5 并在Sublime的HTML文件中按Tab键时,Emmet自动完成将其转换为:

<!DOCTYPE html>
  <html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Document</title>
  </head>
  <body>

  </body>
</html>

但是当我在扩展名为.php的文件中执行相同操作时,按下选项卡将不会发生任何事情 . 它是一个崇高的配置问题,还是有任何解决方案,用于在Sublime中使用Emmet快速键入HTML代码的PHP文件?

1 回答

  • 1

    Emmet的自述文件Package Control page清楚地解释了如何执行此操作 - 向下滚动到 How to expand abbreviations with Tab in other syntaxes 部分:

    Emmet仅扩展有限语法的缩写:HTML,CSS,LESS,SCSS,Stylus和PostCSS . 将Tab处理程序限制为有限语法列表的原因是因为它破坏了原生Sublime Text片段 . 如果要在其他语法中使用Tab缩写(例如,JSX,HAML等),则必须调整键盘shorcuts设置:为tab键添加expand_abbreviation_by_tab命令,以获取所需的语法范围选择器 . 要获取当前语法范围选择器,请按⇧^P(OSX)或Ctrl Alt Shift P,它将显示在编辑器状态栏中 . 转到首选项>键绑定 - 用户,并使用正确配置的范围选择器而不是SCOPE_SELECTOR标记插入以下JSON代码段:

    {
      "keys": ["tab"], 
      "command": "expand_abbreviation_by_tab", 
    
      // put comma-separated syntax selectors for which 
      // you want to expandEmmet abbreviations into "operand" key 
      // instead of SCOPE_SELECTOR.
      // Examples: source.js, text.html - source
      "context": [
        {
          "operand": "SCOPE_SELECTOR", 
          "operator": "equal", 
          "match_all": true, 
          "key": "selector"
        }, 
    
        // run only if there's no selected text
        {
          "match_all": true, 
          "key": "selection_empty"
        },
    
        // don't work if there are active tabstops
        {
          "operator": "equal", 
          "operand": false, 
          "match_all": true, 
          "key": "has_next_field"
        }, 
    
        // don't work if completion popup is visible and you
        // want to insert completion with Tab. If you want to
        // expand Emmet with Tab even if popup is visible -- 
        // remove this section
        {
          "operand": false, 
          "operator": "equal", 
          "match_all": true, 
          "key": "auto_complete_visible"
        }, 
        {
          "match_all": true, 
          "key": "is_abbreviation"
        }
      ]
    }
    

    PHP的 SCOPE_SELECTOR 值是 embedding.php text.html.basic .

相关问题