2013-08-16 50 views
0

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

例如:我需要绑定一个命令将光标向下移动到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"}] 
} 

回答

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争议)