2

I am using Sublime Text 2 on Windows 7, I have configured it to use 2 columns for split editing (in menu: View > Layout > Columns: 2), so now I have 2 panes. When I open new file through Total Commander F4 Edit or Explorer's context menu "Open with Sublime Text 2" then the new file is opened in currently active pane, this is not a problem when left pane is active, but when right pane is active then it opens it in right pane, which is the behavior I do not want. Is it possible to always open new files for editing in left pane? If so, how do I do that?

Czarek.

1 Answer 1

2

There's no native way to do this in Sublime Text 2. What you want is to be able to switch to the left window group (group 0), open a file, and then (possibly, its not clear from your question) switch back to the right window group (group1).

This can be accomplished with a series of Sublime Text Commands. Specifically move_to_group,prompt_open_file,move_to_group.

Unfortunately, Sublime's native capability for stringing together commands, macros, only works on text manipulation commands, not window commands. And keybindings only accept single commands. So you have 2 options

Plugin-free option

Just type Ctrl+1 before you hit Ctrl+O. This is a fairly quick way to switch to the left window group and open the file. You can then use Ctrl+2 to switch back afterwards if needed.

The full (more involved) solution

You can install the plugin code found on Sublime's forums to create a "run multiple commands" command. You can then create a keybinding for what you want. I'm guessing you would want it to just override the default open option, so lets bind it to 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"}
          ]}}

This will then work after you install the plugin from the link, reproduced below. To install it, you can just install it as a .py file in your %APPDATA%\Sublime Text 2\Packages\User folder.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .