首页 > 解决方案 > Search selected text in all workspace files without having to hit the enter key to actually start the search?

问题描述

I know how to search the selected text just by Ctrl-Shift-F, then enter key. I want to these two steps to be one keybinding. How can i achieve this?

标签: visual-studio-code

解决方案


使用我的扩展查找和转换

和这个键绑定:

{
  "key": "alt+shift+f",                     // whatever keybinding you wish
  "command": "runInSearchPanel",
  "args": {

     // open Search Panel with current workspace as the `files to include`
    "filesToInclude": "${workspaceFolder}",
    "triggerSearch": true
  }
}

这很容易。演示:

无选择地搜索

您还可以保存查找/替换参数以重复使用等等。


这也有效:

  1. 安装 macrosRe 扩展macrosRe - 这允许您使用单个键绑定运行多个命令。[或尝试多命令扩展]。

  2. 在你的 settings.json 中创建这个宏命令:

    "macros": {
      "findInAllFiles": [
        "workbench.action.findInFiles",
        "search.action.refreshSearchResults"
      ]
    }
    
  3. 在您的 keybindings.json 中为该宏创建一个键绑定:

    {
      "key": "ctrl+. ctrl+.",
      "command": "macros.findInAllFiles"
    }
    

我使用Ctrl- . Ctrl-.只是为了确保它是独一无二的。但它也适用于Ctrl- Shift- F,该workbench.action.findInFiles命令的默认键绑定。

  1. 重新加载或重新启动 vscode! 必须这样做。
  2. 选择要在所有文件中搜索的术语 - 您不必复制它,只需选择它即可。
  3. 在上面执行您选择的键绑定。

推荐阅读