0

如何将某些命令与重复绑定?

例如:我需要绑定一个命令将光标下移到 10 行。一行是这样的:

{ "keys": ["alt+j"], "command": "set_motion", "args": {
    "motion": "move",
    "motion_args": {"repeat": 1,"by": "lines", "forward": true, "extend": true },
    "linewise": true },
    "context": [{"key": "setting.command_mode"}]
}
4

1 回答 1

0

写一个插件:

import sublime, sublime_plugin

class CommandWithRepeats(sublime_plugin.TextCommand):
    def run(self, edit, repeats, **args): 
        for x in xrange(repeats):
            self.view.run_command(args['command'], args['args'])

然后我们可以在键绑定中添加任何带有重复的命令:

"keys": ["alt+j"],
"command": "command_with_repeats",
"context": [{"key": "setting.command_mode"}],
"args": {
    "repeats": 10,
    "command": "set_motion",
    "args": {
        "motion": "move",
        "motion_args": {
            "by": "lines",
            "forward": true,
            "extend": true
        },
        "linewise": true
    }
}

包装任何命令command_with_repeats()并执行几次(repeats争论)

于 2013-09-10T11:47:16.190 回答