Sublime Text 2의 왼쪽 창/열에서 새 파일을 강제로 열려면 어떻게 해야 합니까?

Sublime Text 2의 왼쪽 창/열에서 새 파일을 강제로 열려면 어떻게 해야 합니까?

저는 Windows 7에서 Sublime Text 2를 사용하고 있으며 분할 편집을 위해 2개의 열을 사용하도록 구성했으므로(메뉴: 보기 > 레이아웃 > 열: 2) 이제 2개의 창이 있습니다. Total Commander F4 Edit 또는 Explorer의 컨텍스트 메뉴 "Sublime Text 2로 열기"를 통해 새 파일을 열면 새 파일이 현재 활성 창에서 열립니다. 왼쪽 창이 활성화되면 문제가 되지 않지만 오른쪽 창이 활성화되면 문제가 됩니다. 오른쪽 창에서 열립니다. 이는 내가 원하지 않는 동작입니다. 편집을 위해 항상 왼쪽 창에서 새 파일을 열 수 있습니까? 그렇다면 어떻게 해야 합니까?

차렉.

답변1

Sublime Text 2에는 이 작업을 수행하는 기본 방법이 없습니다. 원하는 것은 왼쪽 창 그룹(그룹 0)으로 전환하고 파일을 연 다음 (아마도 질문에서 명확하지 않을 수 있음) 다시 전환할 수 있는 것입니다. 오른쪽 창 그룹(group1).

이는 일련의 작업을 통해 수행할 수 있습니다.숭고한 텍스트 명령. 특히 move_to_group,prompt_open_file,move_to_group.

불행하게도 명령, 매크로를 함께 묶는 Sublime의 기본 기능은 창 명령이 아닌 텍스트 조작 명령에서만 작동합니다. 그리고 키 바인딩은 단일 명령만 허용합니다. 따라서 두 가지 옵션이 있습니다

플러그인이 필요 없는 옵션

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)

관련 정보