
私は Windows 7 で Sublime Text 2 を使用しており、分割編集用に 2 つの列を使用するように構成しています (メニュー: 表示 > レイアウト > 列: 2)。そのため、2 つのペインがあります。Total Commander F4 編集またはエクスプローラーのコンテキスト メニュー「Sublime Text 2 で開く」で新しいファイルを開くと、新しいファイルは現在アクティブなペインで開かれます。これは、左ペインがアクティブな場合は問題になりませんが、右ペインがアクティブな場合は右ペインで開かれます。これは望ましくない動作です。編集用に新しいファイルを常に左ペインで開くことは可能ですか? 可能であれば、どのようにすればよいですか?
チャレク。
答え1
Sublime Text 2 では、これをネイティブに実行する方法はありません。必要なのは、左のウィンドウ グループ (グループ 0) に切り替えてファイルを開き、(おそらく、質問からは明らかではないかもしれませんが) 右のウィンドウ グループ (グループ 1) に戻ることです。
これは一連の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"}
]}}
これは、以下に再現したリンクからプラグインをインストールすると機能します。インストールするには、%APPDATA%\Sublime Text 2\Packages\User フォルダーに .py ファイルとしてインストールするだけです。
# 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)