visual-studio-code - 搜索(在文件中查找)键绑定(bind)可以带参数,workbench.view.search 不能 - 其他区别?

标签 visual-studio-code

我只想知道 workbench.action.findInFilesworkbench.view.search 命令之间的区别。两者都用于访问跨文件搜索面板。

我猜 workbench.action.findInFilesworkbench.view.search 的更新版本,因为我找到了 'findInFiles' accepts parametersview.search 没有。

引用:https://github.com/microsoft/vscode/blob/cadabab73fef89fe0c4bfe23b5a33cd58e39ea9c/src/vs/workbench/services/search/common/search.ts#L24

最佳答案

我认为您捕获了唯一真正的区别。它们都有相同的默认键绑定(bind),但 view 版本确实有一个 context 参数:

!searchViewletVisible

所以它实际上只是在不可见时显示搜索面板。但是 findInFiles 版本也会使搜索面板可见。唯一真正的区别是接受争论的能力——我认为很少有人知道这一点。

正如您所指出的,findInFiles 版本可以带参数——我以前不知道!!所以值得展示如何。像这样:

  {
    "key": "ctrl+shift+f",                    // whatever keybinding you wish
    "command": "workbench.action.findInFiles",
    "args": {

      "query": "${selectedText}",                  // variables don't work
      "replace": "that's $1 swell",
      "triggerSearch": true,                       // seems to be the default
      "filesToInclude": "${relativeFileDirname}",  // no variables
      "preserveCase": true,
      "useExcludeSettingsAndIgnoreFiles": false,
      "isRegex": true, 
      "isCaseSensitive": true,
      "matchWholeWord": true,
      "filesToExclude": "./*.css"
    }
  },

workbench.view.search 可用参数的完整列表:

   "query": "",
   "regexp": "",
   "wholeWord": "",
   "caseSensitive": "",
   "includes": "",
   "excludes": "",
   "showIncludesExcludes": "",
   "useIgnores": "",
   "contextLines": 0,
   "triggerSearch": "",
   "focusResults": 

上面的 args 列表正在转换为下面的列表(参见 https://github.com/microsoft/vscode/commit/2fdc8c336c601e385fadfaa1802cdc67fea96241 )以与 findInFiles 命令保持一致。我假设旧的 args 会工作一段时间,但新的 args 在 Insiders' Build v1.51 中,所以应该很快就会稳定。

  "query": ""
  "isRegexp": true,
  "isCaseSensitive": false,
  "matchWholeWord": true,
  "filesToInclude": "",
  "filesToExclude": "",
  "showIncludesExcludes": false,
  "useExcludeSettingsAndIgnoreFiles": true,
  "contextLines": 2,
  "triggerSearch": true,
  "focusResults": true

如果您有一个常用的搜索/替换,这可能很有值(value)并且可以分配给唯一的键绑定(bind)。


workbench.view.search 不能接受预设参数,但是 search.action.openNewEditor 可以!参见 https://stackoverflow.com/a/62207896/836330了解更多。

关于visual-studio-code - 搜索(在文件中查找)键绑定(bind)可以带参数,workbench.view.search 不能 - 其他区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62251045/

相关文章:

unit-testing - 如何为 vscode 扩展做 Coverage 导出

python - 同时运行多个python脚本

visual-studio-code - VSCode 插件和关于 alpha 版本的想法

visual-studio-code - 如何在 VS Code 中更改 block 关系线颜色

javascript - VS 代码片段到当前行下方的 console.log 选择

visual-studio-code - 如何在VSCode中搜索方法?

git - Visual Studio Code 中的 U 和 M 文件标记是什么?

atom-editor - 将智能感知添加到 Atom

debugging - Visual Studio Code 未在 OS X 上加载符号

vb.net - 使用 Visual Studio 代码,编码 vb.net,如何启动我的程序然后进入 Debug模式?