SublimeText2键绑定可以映射到包命令,例如“SublimeREPL:Ruby”吗?

时间:2012-09-06 20:53:02

标签: sublimetext2 key-bindings

我正在尝试创建一个用于在ST2中打开SublimeREPL:Ruby窗口的键绑定,但我不确定您是否可以为非基本命令创建快捷方式。

我在http://sublimetext.info/docs/en/reference/key_bindings.html周围搜索并搜索了我的小心脏,但找不到任何关于为外国包创建键绑定的信息。

第2个想法(我是1y / o dev) - 我决定浏览包文件。我在/Users/administrator/Library/Application Support/Sublime Text 2/Packages/SublimeREPL/config/Ruby中找到了这个:

[
 {
    "id": "tools",
    "children":
    [{
        "caption": "SublimeREPL",
        "mnemonic": "r",
        "id": "SublimeREPL",
        "children":
        [
            {"command": "repl_open", 
             "caption": "Ruby",
             "id": "repl_ruby",
             "mnemonic": "r",
             "args": {
                "type": "subprocess",
                "external_id": "ruby",
                "encoding": "utf8",
                "cmd": {"windows": ["irb.bat", "--noreadline", "--inf-ruby-mode"],
                        "linux": ["irb", "--noreadline", "--inf-ruby-mode"],
                        "osx": ["irb", "--noreadline", "--inf-ruby-mode"]},
                "soft_quit": "\nexit\n",
                "cwd": "$file_path",
                "cmd_postfix": "\n", // postfix 
                "suppress_echo": true,
                "syntax": "Packages/Ruby/Ruby.tmLanguage"
                }
            }
        ]   
    }]
}
]

我创建了键绑定:{ "keys": ["super+i", "super+r", "super+b"], "command": "repl_open" }

但没有骰子。有任何想法吗?重启ST2可能吗?

1 个答案:

答案 0 :(得分:2)

定义快捷键时,应该为repl_open命令提供它在您提供的菜单项声明中获得的参数。

尝试以下方法(未经测试,但与REPL中其他环境的配置非常相似):

{ "keys": ["super+i", "super+r", "super+b"], "command": "repl_open", "args":
   {
        "type": "subprocess",
        "external_id": "ruby",
        "encoding": "utf8",
        "cmd": {"windows": ["irb.bat", "--noreadline", "--inf-ruby-mode"],
            "linux": ["irb", "--noreadline", "--inf-ruby-mode"],
            "osx": ["irb", "--noreadline", "--inf-ruby-mode"]},
        "soft_quit": "\nexit\n",
        "cwd": "$file_path",
        "cmd_postfix": "\n", // postfix 
        "suppress_echo": true,
        "syntax": "Packages/Ruby/Ruby.tmLanguage"
   }
}

一个更简单的选项(但可配置性较差)只是直接调用菜单项(再次,未测试但与我的配置类似):

{ "keys": ["super+i", "super+r", "super+b"],
  "command": "run_existing_window_command", "args":
    {
        "id": "repl_ruby",
        "file": "config/Ruby/Main.sublime-menu"
    }
},