
我在 Windows 7 上使用 Sublime Text 2,我已將其配置為使用 2 列進行分割編輯(在功能表中:視圖 > 佈局 > 列:2),所以現在我有 2 個窗格。當我透過Total Commander F4 Edit 或資源管理器的上下文功能表「使用Sublime Text 2 開啟」開啟新檔案時,新檔案將在目前活動窗格中打開,當左窗格處於活動狀態時,這不是問題,但當右窗格處於活動狀態時,這不是問題它在右窗格中打開它,這是我不想要的行為。是否可以始終在左側窗格中開啟新檔案進行編輯?如果是這樣,我該怎麼做?
查雷克。
答案1
在 Sublime Text 2 中沒有本地方法可以做到這一點。視窗群組(group1)。
這可以透過一系列的操作來完成Sublime Text 指令。具體來說就是 move_to_group、prompt_open_file、move_to_group。
不幸的是,Sublime 的本機連線指令、巨集的功能僅適用於文字操作指令,不適用於視窗指令。並且鍵綁定僅接受單一命令。所以你有2個選擇
無外掛選項
只需在按 Ctrl+O 之前鍵入 Ctrl+1。這是切換到左側視窗群組並打開檔案的相當快速的方法。如果需要,您可以使用 Ctrl+2 切換回來。
完整(更複雜)的解決方案
您可以安裝在 Sublime 論壇上找到的插件程式碼建立“運行多個命令”命令。然後,您可以根據需要建立鍵綁定。我猜您希望它只覆蓋預設的開啟選項,所以讓我們將其綁定到 Ctrl+O
{ "keys": ["ctrl+o"],
"command": "run_multiple_commands",
"args": {
"commands": [
{"command": "move_to_group", "args": {"group": 0 }, "context": "window"},
{"command": "prompt_open_file", "context": "window"},
{"command": "move_to_group", "args": {"group": 1 }, "context": "window"}
]}}
從下面複製的連結安裝插件後,這將起作用。要安裝它,您只需將其作為 .py 檔案安裝在 %APPDATA%\Sublime Text 2\Packages\User 資料夾中即可。
# run_multiple_commands.py
import sublime, sublime_plugin
# Takes an array of commands (same as those you'd provide to a key binding) with
# an optional context (defaults to view commands) & runs each command in order.
# Valid contexts are 'text', 'window', and 'app' for running a TextCommand,
# WindowCommands, or ApplicationCommand respectively.
class RunMultipleCommandsCommand(sublime_plugin.TextCommand):
def exec_command(self, command):
if not 'command' in command:
raise Exception('No command name provided.')
args = None
if 'args' in command:
args = command['args']
# default context is the view since it's easiest to get the other contexts
# from the view
context = self.view
if 'context' in command:
context_name = command['context']
if context_name == 'window':
context = context.window()
elif context_name == 'app':
context = sublime
elif context_name == 'text':
pass
else:
raise Exception('Invalid command context "'+context_name+'".')
# skip args if not needed
if args is None:
context.run_command(command['command'])
else:
context.run_command(command['command'], args)
def run(self, edit, commands = None):
if commands is None:
return # not an error
for command in commands:
self.exec_command(command)