3中为多个插件添加快捷键

3中为多个插件添加快捷键

本文介绍了在Sublime Text 3中为多个插件添加快捷键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Sublime Text 3中使用CodeFormatter和SassBeautify插件,以便为.scss文件以及.js/.html文件提供语法突出显示和格式设置.我已经能够为这两个插件设置快捷键,但不能同时为两个插件设置快捷键,具体取决于我所在的文件类型.

I'm using CodeFormatter and SassBeautify plugins in Sublime Text 3 in order to provide syntax highlighting and formatting for .scss files as well as .js/.html files. I've been able to set up shortcut keys for either plugin, but not to work for both, depending on the type of file I'm in.

[{
    "keys": ["ctrl+alt+f"],
    "command": "sass_beautify"
}, {
    "keys": ["ctrl+alt+f"],
    "command": "code_formatter"
}]

有人可以建议如何做吗?我试图理解上下文",但做起来还不够.

Can someone suggest how do to it? I've tried to understand "contexts" but not well enough to do this.

我做错了吗?我应该有另一种方式实现这一目标吗?

Am I doing this all wrong? Is there another way I should be achieving this?

更正的键盘映射文件:

[{
    "keys": ["ctrl+alt+f"],
    "command": "sass_beautify",
    "context": [{
        "key": "selector",
        "operator": "equal",
        "operand": "source.scss"
    }]
}, {
    "keys": ["ctrl+alt+f"],
    "command": "code_formatter",
    "context": [{
        "key": "selector",
        "operator": "not_equal",
        "operand": "source.scss"
    }]
}]

推荐答案

添加与以下内容类似的内容作为上下文条目

Add something similar to the following as a context entry

{ "key": "selector", "operator": "equal", "operand": "source.scss", "match_all": true }

{ "key": "selector", "operator": "equal", "operand": "(text.html, source.js)", "match_all": true }

操作数值是作用域条目.在状态栏中有一个特定于平台的键绑定以显示作用域,但是我不记得它们是什么.我个人使用 https://github.com/facelessuser/ScopeHunter 来检查范围.

The operand values are scope entries. There is a platform specific key binding to display scopes in the status bar, but I don't recall what they are off the top of my head. I personally use https://github.com/facelessuser/ScopeHunter to inspect scopes.

这篇关于在Sublime Text 3中为多个插件添加快捷键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 11:43