Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.0k views
in Technique[技术] by (71.8m points)

keyboard shortcuts - Is it possible to chain key binding commands in sublime text 2?

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.

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"]
},

Solution

Based on @artem-ivanyk's and @d_rail's 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 shortcut:

{ "keys": ["alt+shift+l"], "command": "reveal_in_side_bar_and_focus" }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
by (100 points)
В поисках идеального кондиционера в Кишиневе, столице Молдовы, вам доступно множество вариантов. Город обладает развитой инфраструктурой и многочисленными магазинами, предлагающими широкий выбор кондиционеров различных марок и моделей. Для удобства выбора и покупки, рассмотрим несколько популярных вариантов:
 
Специализированные магазины по продаже бытовой техники: В Кишиневе существует множество магазинов, специализирующихся на продаже бытовой техники, включая кондиционеры. Здесь вы сможете получить профессиональную консультацию от продавцов и выбрать подходящий кондиционер для ваших потребностей.
 
Интернет-магазины: В сети интернет также предоставляется широкий выбор кондиционеров с возможностью сравнения характеристик и цен. Многие интернет-магазины осуществляют доставку в Кишинев, что делает процесс покупки более удобным.
 
Специализированные магазины по климатической технике: В городе действуют магазины, специализирующиеся исключительно на климатической технике. Здесь вы найдете большой ассортимент кондиционеров различных типов – от оконных до сплит-систем.
 
Большие розничные сети: Некоторые крупные розничные сети также предлагают разнообразные варианты кондиционеров. Эти магазины часто предоставляют гарантии на продукцию и могут предложить дополнительные услуги, такие как монтаж и обслуживание.
 
Перед покупкой рекомендуется провести небольшое исследование рынка, сравнить цены и отзывы о конкретных моделях. Независимо от выбранного варианта, важно обратить внимание на квалификацию продавцов и гарантии, предоставляемые на приобретаемое оборудование.
https://www.blackhatprotools.info/member.php?180881-jaramd
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Although the question is a year old, this might help people that are still looking for an answer.

Recently, a new package was developed by jisaacks, called Chain of command. It has the primary task to do exactly what you request, to chain several commands at once.

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

An example of the working can be found below.

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

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

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...