Mac版Sublime Text 3按command+f显示替换界面并将选中的文本填充到搜索框内

1、执行以下命令,安装run_multiple_commands插件:

cat > ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/User/run_multiple_commands.py << EOF
# 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:
        # Workaround for sublime-evernote package, modified by Chien Chun
        pass
        # values = ','.join(str(v) for v in context_name)
        # raise Exception('Invalid command context "'+values+'".')


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

2、Sublime Text->Preferences->Key Bindings,在右侧(User)最外层[]中添加如下配置,添加完后,马上生效,不需要重启Sublime Text。以下配置交换了搜索和替换的快捷键,按command+f显示替换界面并将选中的文本填充到搜索框内(执行多个命令),按command+alt+f显示搜索界面。

{ 
    "keys": ["super+alt+f"],
    "command": "show_panel",
    "args": {"panel": "find", "reverse": false}
},
{
    "keys": ["super+f"],
    "command": "run_multiple_commands",
    "args": {
        "commands": [
            {
                "command": "show_panel",
                "args": {"panel": "replace", "reverse": false},
                "context": "window"
            },
            {
                "command": "slurp_find_string",
                "context": "window"
            }
        ]
    }
}

标签: Mac版Sublime Text 3按command+f显示替换界面并将选中的文本填充到搜索框内

添加新评论