0

I want to write a keybinding to type something into a non-editor input box in VS Code, such as the query editor input box in the Search View or the Editor Find Widget.

I tried to use the "type" command like so:

{
    "key": ...,
    "command": "type",
    "args": { "text": "hello world" }
},

But that didn't do what I expected. It seemed to have no effect in the Search View's query editor input box, and with the Editor Find Widget's input box, it ended up typing the text argument into the editor itself instead, so I assume this command is just for typing into editors.

How can this be done? (ideally without the usage of extensions, but an answer using extensions is still acceptable) Or is it not possible at all?


I tried googling "github vscode issues keyboard shortcut "type" into input box" and didn't see anything useful in the top search results. Neither for searching "is:q keyboard shortcut [vscode] type input box" in Stack Overflow's search bar.

starball
  • 20,030
  • 7
  • 43
  • 238

1 Answers1

0

I don't know if there are any input boxes in vscode where you can open it, focus it, and then add text to it. You probably have to open it in the first place with arguments to its command. So those arguments will differ for each type of input box.

Specifically for the Find Widget, you would use this:

    "command": "editor.actions.findWithArgs",
    "args": {
      // "findInSelection": true,      // doesn't work
      "matchCase": false,              // should be isCaseSensitive
      // "matchCaseOverride": 0,       // appears to not be implemented
      // "preserveCase": true,        
      // "preserveCaseOverride": 0,    // appears to not be implemented
      "isRegex": true,
      // "regexOverride": 1,           // appears to not be implemented
      "searchString": "some queryString",
      "replaceString": "a replacement string"
      // "wholeWord": true,            // should be matchWholeWord
      // "wholeWordOverride": 0        // appears to not be implemented
    }

For searching across files, you can use these arguments:

    "command": "workbench.action.findInFiles",
    "args": {
      "query": "(enum|struct|fn|trait|impl(<.*>)?|type) ",
      "isRegex": true,
      "replace": "$1",
      // "triggerSearch": true,          // seems to be the default
      "filesToInclude": "src, include",  // no variables in findInFiles
      // "preserveCase": true,
      // "useExcludeSettingsAndIgnoreFiles": false,
      // "isCaseSensitive": true,
      // "matchWholeWord": true,
      // "filesToExclude": ""
    }

You can use these commands with their args in a macro extension or the built-in runCommands.

starball
  • 20,030
  • 7
  • 43
  • 238
Mark
  • 143,421
  • 24
  • 428
  • 436