是否可以将键绑定命令链接到sublime文本2中? [英] Is it possible to chain key binding commands in sublime text 2?
问题描述
在Sublime Text中,有时我想在侧栏中显示当前文件,然后在文件夹结构中导航.
There are times in Sublime Text when I want to reveal the current file in the side bar and then navigate around the folder structure.
这可以使用命令reveal_in_side_bar
和focus_side_bar
来实现,但是它们必须绑定到两个单独的按键组合,因此,在理想情况下,我只需要一个键盘(I (很懒).
This can be achieved using the commands reveal_in_side_bar
and focus_side_bar
however they have to be bound to two separate key combinations so I have to do 2 keyboard combinations to achieve my goal when ideally I'd like just one (I'm lazy).
是否可以将多个命令绑定到单个组合键?例如像这样的东西:
Is there any way to bind multiple commands to a single key combination? e.g. something like this:
{
"keys": ["alt+shift+l"],
"commands": ["reveal_in_side_bar", "focus_side_bar"]
},
解决方案
基于@ artem-ivanyk和@d_rail的答案
Solution
Based on @artem-ivanyk's and @d_rail's answers
1)工具→新插件
import sublime, sublime_plugin
class RevealInSideBarAndFocusCommand(sublime_plugin.WindowCommand):
def run(self):
self.window.run_command("reveal_in_side_bar")
self.window.run_command("focus_side_bar")
另存为RevealInSideBarAndFocus.py
Save as RevealInSideBarAndFocus.py
2)Sublime Text 2→首选项→按键绑定-用户
将其绑定到快捷方式:
{ "keys": ["alt+shift+l"], "command": "reveal_in_side_bar_and_focus" }
推荐答案
更新@Artem Ivanyk的答案.我不知道Sublime中发生了什么变化,但是该解决方案对我而言不起作用,但我可以使它起作用:
Updating @Artem Ivanyk's answer. I do not know what changed in Sublime, but that solution did not work for me, but I got this to work:
import sublime, sublime_plugin
class RevealInSideBarAndFocusCommand(sublime_plugin.WindowCommand):
def run(self):
self.window.run_command("reveal_in_side_bar")
self.window.run_command("focus_side_bar")
.
{ "keys": ["ctrl+shift+8"], "command": "reveal_in_side_bar_and_focus" }
顺便说一句,我正在使用内部版本2220
Btw, I'm using Build 2220
这篇关于是否可以将键绑定命令链接到sublime文本2中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!