【问题标题】:Sublime Text 3 - apply shortcut only to specific file typesSublime Text 3 - 仅将快捷方式应用于特定文件类型
【发布时间】:2017-01-01 20:13:02
【问题描述】:

我正在使用 Sublime Text 3,我安装了 JSFormat 来格式化我的 .js 文件并配置键绑定,如下所示:

{ "keys": ["ctrl+shift+f"], "command": "js_format" }

现在,我还希望能够格式化我的 .css.html 文件,所以我找到了这个快捷方式:

{ "keys": ["ctrl+shift+f"], "command": "reindent" , "args": { "single_line": false } }

我想将js_format 用于我的.js 文件,并将reindent 用于我的.css.html 文件。

是否可以为每个快捷方式指定文件类型?

【问题讨论】:

标签: keyboard-shortcuts sublimetext3 sublimetext


【解决方案1】:

更新

后来我发现这是Sublime Text 3: how to bind a shortcut to a specific file extension?的副本

原答案

添加context

{
  "keys": ["ctrl+shift+f"],
  "command": "js_format",
  "context": [
    {
      "key": "selector",
      "operator": "equal",
      "operand": "source.js"
    }
  ]
}

重要的部分是将operand 设置为source.js。您可以将js 替换为您想要的任何文件扩展名。您还可以使用逗号指定其他来源。例如,这会导致命令应用于所有 .html.css 文件:

{ "key": "selector", "operator": "equal", "operand": "source.html, source.css" }

请参阅unofficial documentation on key bindings

【讨论】:

    猜你喜欢
    • 2015-11-27
    • 1970-01-01
    • 1970-01-01
    • 2018-02-11
    • 1970-01-01
    • 2017-01-28
    • 2021-08-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多