2013-08-16 47 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爭議)