我只想知道 workbench.action.findInFiles
和 workbench.view.search
命令之间的区别。两者都用于访问跨文件搜索面板。
我猜 workbench.action.findInFiles
是 workbench.view.search
的更新版本,因为我找到了 'findInFiles' accepts parameters而 view.search
没有。
最佳答案
我认为您捕获了唯一真正的区别。它们都有相同的默认键绑定(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/