如何使用预先填充的搜索字符串显示查找和替换面板?

时间:2016-07-22 06:39:57

标签: sublimetext3 sublime-text-plugin

我知道可以显示Sublime Text"查找和替换"使用show_panel命令(通过键绑定或插件)控制面板,并控制启用/禁用哪些参数。

从Sublime Console面板运行的示例:

window.run_command('show_panel', { 'panel': 'replace', 'regex': True, 'case_sensitive': False, 'whole_word': False, 'in_selection': False, 'wrap': True, 'highlight': True, 'preserve_case': True })

我想知道的是:有没有办法预先填充Find What:Replace With:值?

我找到this forum post但没有回复,unofficial documentation在这种情况下无济于事。

我试过了:

  • 'find_what': 'string'
  • 'replace_with': 'string'
  • 'find_history': 'string'
  • 'replace_history': 'string'
  • 'find_history': ['string']
  • 'replace_history': ['string']
  • 'find': 'string'
  • 'replace': 'string'
编辑:我也尝试过:

  • characters
  • find_characters
  • look_for
  • search_for
  • find_regex
  • find_string
  • search_string
  • replacement
  • search_characters

并且以上都没有任何区别 - 面板总是预先填充了之前的搜索和替换值,而不是我传入的值。

我知道命令slurp_find_stringslurp_replace_string,它们将分别采用当前选择并更新Find What / Replace With值,但我想要一种方法要做到这一点,而不必先考虑选择 - 我只想将值作为参数直接传递给show_panel命令。

有谁知道可以使用哪些参数/参数来控制它?

2 个答案:

答案 0 :(得分:1)

我想对打开一个打包工具并使用“查找搜索”窗口的键绑定命令执行相同的操作。最后,我得到了易于定制的东西,并且可以用于仅使用另一个键绑定的任何命令。

运行打包工具后,我仅使用此键绑定来插入文本(在我的情况下,这是一个复杂的正则表达式)。对我来说,在OSX上,它被直观地记住为(插入1) CMD + i CMD + 1

打开Sublime Text / Preferences / Key Bindings

将此添加到User - Default (OS).sublime-keymap

{ "keys": ["super+i", "super+1"], "command": "insert", "args": { "characters": "my-custom-insert-text1" } },
{ "keys": ["super+i", "super+2"], "command": "insert", "args": { "characters": "my-custom-insert-text2" } },

// etc..

答案 1 :(得分:0)

您可以在运行show_panel命令后立即在窗口上运行insert命令。

import sublime_plugin


class ShowPanelPrefilledCommand(sublime_plugin.WindowCommand):
    def run(self, interactive=True):
        self.window.run_command('show_panel', {
            'panel': 'find_in_files',
            'where': '<open folders>',
            'whole_word': False,
            'case_sensitive': False,
            'preserve_case': False,
            'regex': False,
            'use_buffer': False,
            'show_context': False,
        })

        self.window.run_command('insert', {'characters': 'hello'})

        if not interactive:
            self.window.run_command('find_all', {'close_panel': True})