Can I bind key binding commands in sublime text 2?

There are times in Sublime Text when I want to show the current file in the sidebar and then navigate the folder structure.

This can be achieved using the reveal_in_side_bar and focus_side_bar , however they should be associated with two separate key combinations, so I have to make 2 key combinations to achieve my goal, when ideally I would like only one (I am lazy).

Can I associate multiple commands with a single key combination? for example something like this:

 { "keys": ["alt+shift+l"], "commands": ["reveal_in_side_bar", "focus_side_bar"] }, 

Decision

Based on @ artem-ivanyk and @d_rail answers

1) Tools β†’ New plugin

 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") 

Save as RevealInSideBarAndFocus.py

2) Sublime Text 2 β†’ Preferences β†’ Key Bindings - User

Bind it to a shortcut:

 { "keys": ["alt+shift+l"], "command": "reveal_in_side_bar_and_focus" } 
+45
sublimetext keyboard-shortcuts
Mar 10 '12 at 12:50
source share
8 answers

Updating @Artem Ivanyk answer. I don't know what has changed in Sublime, but this solution did not work for me, but I got this for 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" } 

Btw, I am using Build 2220

+28
Nov 02
source share

Although the question is a year, it can help people who are still looking for an answer.

Recently, a new package was developed by jisaacks called Chain of command . He has the main task of doing exactly what you request for several teams at once.

The package can be found here: https://github.com/jisaacks/ChainOfCommand

An example of work is given below.

Let's say you need a key binding to duplicate the current file. You can set this key binding:

 { "keys": ["super+shift+option+d"], "command": "chain", "args": { "commands": [ ["select_all"], ["copy"], ["new_file"], ["paste"], ["save"] ] } } 

This will select all the text, copy it, create a new file, paste the text and open the save file dialog.

Source: https://sublime.wbond.net/packages/Chain%20of%20Command .

+31
Mar 31 '14 at 13:27
source share

I came across a similar problem. When I tried to record macros in which the Save command was involved, the console threw me the message <Unknown save command macro. It worked with an elementary plugin.

1) Tools β†’ New plugin

 import sublime, sublime_plugin class MyChainedActionsCommand(): def run(self): self.view.run_command("reveal_in_side_bar") self.view.run_command("focus_side_bar") 

You need to use the top camel notation for the class name. ST2 provides this class for the command name with the suffix "Command", and the rest is converted to a lowercase letter. I. in this example, MyChainedActionsCommand can be run in a strict console: view.run_command("my_chained_actions")

2) Sublime Text 2 β†’ Preferences β†’ Key Bindings - User

Bind it to a shortcut:

{ "keys": ["alt+shift+l"], "command": "my_chained_actions" }

Commas

+23
Jun 02 2018-12-12T00:
source share

Take a look at this meaning .

I tried to realize this for a long time and found it by accident.

Remember to read the provided β€œdocumentation”. I kept trying to do this work until I reworked. I did not pass the context key.

+8
Feb 08 '13 at 7:28
source share

You can create a macro for this. For Sublime Text, macros are essentially just a series of commands. Then you create a binding for this macro. You can create a macro using Tools > Record Macro , and then execute your commands (beware that macros record keystrokes, so you want to use commands from the menu bar to avoid conflicts), then Stop Recording , then Save Macro . After saving the macro, you can open it in Sublime Text to make sure that it writes only what you want.

+4
Mar 10 '12 at 13:05
source share

Based on Artem Ivanyk's answer, here is the version of ChainedActions that works with arguments. actions and args require two arguments. Both are lists, and each command in the list is executed with the corresponding arguments. This admittedly stupid example inserts two fragments: view.run_command("chained_actions", {"actions":["insert_snippet","insert_snippet"],"args":[{"contents": " ($ 0) "}, {" contents ":" 1 ($ 0) "}]})` `

 import sublime import sublime_plugin class ChainedActionsCommand(sublime_plugin.TextCommand): def run(self, edit, actions, args): for i, action in enumerate(actions): self.view.run_command(action, args[i]) 
+1
Jan 14 '14 at 20:28
source share

I tried to use the same command, but in the end I got an error: when the folder with the file is already expanded, the sublime moved my focus sidebar, where I see open files. To improve this behavior, I wrote a new plugin that guarantees that it will behave the way I want, here https://github.com/miguelgraz/FocusFileOnSidebar

+1
Jun 11 '14 at
source share

I use Sublime text3 build - 3083. It solves the problem, just "Show it in the sidebar", the focus comes automatically.

I added a special key combination for "Reveal in sidebar", adding the following instruction in the section "Preferences-> Key Bindings-User:

 [ { "keys": ["ctrl+shift+r"], "command": "reveal_in_side_bar"} ] 

The option "Show in the sidebar" is not available for image file types, since the context menu does not appear with a right mouse click. In this situation, a convenient key combination is convenient.

+1
Jul 08 '15 at 8:55
source share



All Articles