【问题标题】:Emmet autocomplete is not working for php files in Sublime (Expand abbreviations)Emmet 自动完成功能不适用于 Sublime 中的 php 文件(展开缩写)
【发布时间】:2017-04-18 23:28:43
【问题描述】:

我在 Sublime 中为 HTML 文件使用 Emmet 插件。但是当我想在 Laravel 中的视图文件等 PHP 文件中键入 HTML 代码时,Emmet 不会扩展缩写。

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

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

  </body>
</html>

但是,当我在扩展名为 .php 的文件中执行相同操作并按 Tab 时,什么都不会发生。是 sublime 的配置问题还是有任何解决方案可以在 Sublime for PHP 文件中使用 Emmet 快速键入 HTML 代码?

【问题讨论】:

    标签: php sublimetext3 emmet


    【解决方案1】:

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

    Emmet 仅以有限的语法扩展缩写:HTML、CSS、LESS、SCSS、Stylus 和 PostCSS。将 Tab 处理程序限制为有限语法列表的原因是因为它破坏了本机 Sublime Text sn-ps。

    如果您想在其他语法(例如 JSX、HAML 等)中使用 Tab 缩写,您必须调整键盘快捷方式设置:为所需语法范围选择器的 tab 键添加 expand_abbreviation_by_tab 命令。要获取当前语法范围选择器,请按 ⇧⌃P (OSX) 或 Ctrl+Alt+Shift+P ,它将显示在编辑器状态栏中。

    转到 Preferences &gt; Key Bindings — User 并插入以下 JSON sn-p 并使用正确配置的范围选择器而不是 SCOPE_SELECTOR 令牌:

    {
      "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

    【讨论】:

      猜你喜欢
      • 2014-03-13
      • 2017-02-28
      • 2012-01-24
      • 2015-11-16
      • 1970-01-01
      • 2019-01-08
      • 1970-01-01
      • 2014-12-04
      • 2012-07-27
      相关资源
      最近更新 更多