Taraflex
@Taraflex
Ищу работу. Контакты в профиле.

Sublime. Как настроить горячие клавиши?

Как настроить горячие клавиши в sublime text 3 так, чтобы в зависимости от расширения открытого файла выполнялись комманды из разных плагинов
Сейчас
[
	{ "keys": ["ctrl+d"], "command": "htmlprettify" }
]

Как мне добавить сюда
[
    { "keys": ["ctrl+d"], "command": "css_comb" }
]

только для css файлов?
  • Вопрос задан
  • 9621 просмотр
Решения вопроса 2
Taraflex
@Taraflex Автор вопроса
Ищу работу. Контакты в профиле.
Решил доработкой одного маленького плагина

UPD 17.05.2018
import sublime
import sublime_plugin


class RunMultipleCommand(sublime_plugin.TextCommand):

    def exec_command(self, command, syntax):
        if not 'command' in command:
            raise Exception('No command name provided.')

        if 'syntax' in command:
            for s in command['syntax']:
                if syntax.find(s) > -1:
                    break
            else:
                return False

        args = None
        if 'args' in command:
            args = command['args']

        # default context is the view since it's easiest to get the other contexts
        # from the view
        context = self.view
        if 'context' in command:
            context_name = command['context']
            if context_name == 'window':
                context = context.window()
            elif context_name == 'app':
                context = sublime
            elif context_name == 'text':
                pass
            else:
                raise Exception('Invalid command context "'+context_name+'".')

        # skip args if not needed
        if args is None:
            context.run_command(command['command'])
        else:
            context.run_command(command['command'], args)
        return True

    def run(self, edit, commands=None):
        if commands is None:
            return  # not an error
        syntax = self.view.settings().get('syntax').split('/')[-1].lower()
        for command in commands:
            if self.exec_command(command, syntax) and command['end']:
                return


Добавил возможность обрыва цепочки команд при помощи end:true
[
{
    "keys": ["ctrl+d"],
    "command": "run_multiple",
    "args":
    {
        "commands": [
        {
            "syntax": ["python"],
            "command": "auto_pep8",
            "args":
            {
                "preview": false
            },
            "end": true
        },
        {
            "syntax": ["css", "scss", "less", "sass"],
            "command": "css_comb",
            "end": true
        },
        {
            "syntax": ["php"],
            "command": "code_formatter",
            "end": true
        },
        {
            "syntax": ["html", "xml", "json"],
            "command": "htmlprettify",
            "end": true
        },
        {
            "syntax": ["javascript", "typescript"],
            "command": "typescript_format_document",
            "end": true
        }]
    }
},
{
    "keys": ["ctrl+shift+c"],
    "command": "color_highlighter_pick_color",
    "context": [
    {
        "key": "color_highlighter.color_highlighter_pick_color"
    }]
}]
Ответ написан
MintTea
@MintTea
1) В ~/.config/sublime-text-3/Packages/User/hello.sublime-macro
[
    {"command": "htmlprettify" },
    {"command": "css_comb" }
]


2) В Preferences >>> Key Bindings - User
[
    {
        "keys": ["ctrl+d"], 
        "command": "run_macro_file",
        "args": {
            "file": "res://Packages/User/hello.sublime-macro"
        },
        "context": [
            {
                "key": "selector",
                "operator": "equal",
                "operand": "source.css"
            }
        ]
    }
]
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы