How to show search and replace panel with pre-filled search bar?

I know that you can show the Sublime Text Find and Replace panel using the show_panel (either with a key binding or with a plugin), and control which arguments are on / off.

Example launch from the Sublime Console panel:

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

What I would like to know is: is there a way to pre-populate the Find What: and Replace With: values?

I found this forum post , but it has no answer, and unofficial documentation will not help in this case.

I tried:

  • 'find_what': 'string'
  • 'replace_with': 'string'
  • 'find_history': 'string'
  • 'replace_history': 'string'
  • 'find_history': ['string']
  • 'replace_history': ['string']
  • 'find': 'string'
  • 'replace': 'string'

EDIT: I also tried:

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

and none of the above has any meaning - the panel is always pre-filled with the previous search and replaces the values, and not what I pass.


I know the slurp_find_string and slurp_replace_string that will take the current selection and update the Find What / Replace With values ​​accordingly, but I would like to do this without getting confused with the choices first - I just want to pass the values ​​as arguments directly to the show_panel .

Does anyone know which parameters / arguments can be used to control this?

+6
source share
2 answers

You can run the insert command in a window immediately after running the show_panel .

 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}) 
+2
source

I wanted to do the same for the key binding command, which opens the Package Tool and uses the Find Search window. In the end, I got something simple to configure and use for any command that just uses a different key binding.

After running the Package Tool, I just use this key binding to insert text (in my case, this is a complex regular expression). For me on OSX, I intuitively remembered how to (insert 1) CMD + i , CMD + 1

Open Sublime Text / Preferences / Key Bindings

Add this to 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.. 
0
source

All Articles