您可以在宏中使用此命令,因为最近添加了对其参数的支持:
{
"command": "editor.actions.findWithArgs",
"args": {
// "findInSelection": false,
// "isCaseSensitive": true,
// "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
// "replaceString": "asdasd",
// "searchString": "qweqwe",
// "matchWholeWord": true,
// "wholeWordOverride": 0 // appears to not be implemented
}
}
这将打开查找小部件并选择正则表达式选项。当然,您可以根据需要使用其他 args - 有些尚未实现,并且智能感知在键绑定中的此命令上做得很差 - 我已指出哪些 args 尚未实现和/或正确的键名。
-----上一个答案--------------
在 v1.46 中可以打开一个新的搜索编辑器(不是搜索面板),带有各种参数,包括正则表达式按钮是打开还是关闭。
看
SearchEditor: Open new editor with args
。所以这行得通:
{
"key": "ctrl+shift+g",
"command": "search.action.openNewEditor",
"args": {
"query": "\\w*",
"regexp": true,
"includes": "${fileDirname}", // restrict to current editor's directory
// "includes": "${file}", // restrict search to current file
"showIncludesExcludes": true,
"contextLines": 3,
},
"when": "editorTextFocus"
},
之前是否选择了正则表达式选项。其他可用参数:
{
query: string,
includes: string,
excludes: string,
contextLines: number,
wholeWord: boolean,
caseSensitive: boolean,
regexp: boolean,
useIgnores: boolean,
showIncludesExcludes: boolean,
// triggerSearch: boolean, // to be in v.47
// focusResults: boolean // to be in v.47
}
在triggerSearch 和focusResults 被添加到稳定版本(大概是1.47)之前,这里有一个宏会立即运行搜索并聚焦第一个结果:
"multiCommand.commands": [
{
"command": "multiCommand.runSearchEditorwithArguments",
"interval": 200, // needs a small delay so results are loaded before focusing them
"sequence": [
{
"command": "search.action.openNewEditor",
"args": {
"query": "(TODO|NOTE|BUG):",
"regexp": true,
"includes": "${fileDirname}",
"showIncludesExcludes": true,
"contextLines": 3,
}
},
"rerunSearchEditorSearch", // runs the search
"search.action.focusNextSearchResult" // focus first result
]
}
]