drw*_*ode 11 key-bindings visual-studio-code vscode-extensions
我似乎找不到可以从 VSCode 键绑定运行的记录命令的良好列表。
在在线 VSCode 文档中,命令指南列出了两种发现命令的方法:
键盘快捷键的命令通常是不带参数的“简单”命令。“高级命令 api”似乎缺少一些非常基本的命令。
例如,在VSCode 键绑定页面上有一个名为“命令参数”的部分,其中包含以下示例条目:
{ "key": "enter", "command": "type",
"args": { "text": "Hello World" },
"when": "editorTextFocus" }
Run Code Online (Sandbox Code Playgroud)
但我没有看到任何地方type记录了该命令。所以我假设可能存在其他几个类似的基本命令,但我不知道在哪里可以找到它们的文档。
不管怎样,我现在真正想要的是一个命令,我可以运行它来在当前编辑器中进行预定义的搜索和替换,指定查找文本、替换文本和选项...如下所示:
{ "key": "ctrl+shift+8",
"command": "findReplaceAll",
"args": {
"findText": "Company(\\w+)",
"replaceText": "User$1"
"options": { "ignoreCase": false, "wholeWord": true, "regex": true }
},
"when": "editorTextFocus" }
Run Code Online (Sandbox Code Playgroud)
findReplaceAll但我在文档中找不到任何这样的命令或类似的东西,但肯定这样的东西一定存在,对吧?
谢谢!
正如 @AurSaraf 指出的那样,即将推出的新工作将允许创建内置方式的命令(或在扩展中使用),以使用预设的查找/替换和选项在当前文件中进行查找。
我已经在 github issues 上发表了评论,试图让 args 与其他类似命令保持一致,但无济于事。以下是键绑定中当前可用的参数:
{
"key": "alt+p",
"command": "editor.actions.findWithArgs",
"args": {
"searchString": "howd\\d", // double-escaped
"replaceString": "qqqq9",
"isRegex": true,
// "regexOverride": 1,
"findInSelection": false,
"matchWholeWord": false,
// "matchCase": false,
// "matchCaseOverride": 0,
"preserveCase": false,
"isCaseSensitive": false
// "preserveCaseOverride": 0,
// "wholeWordOverride": 0
}
}
Run Code Online (Sandbox Code Playgroud)
注释掉的参数不可用,尽管智能感知显示它们是可用的 - 因此该命令仍然有点“粗糙” - 目前仅在 Insiders Build 中可用。 不要依赖智能感知按键args- 其中许多按键此时命名错误或不起作用。
另请注意,出于某种原因,此命令当前使用 和query,而不是(打开新搜索编辑器)键绑定中使用的和。replaceworkbench.action.findInFilessearch.action.openEditorsearchStringreplaceString
要获得一个强大的扩展来执行大量预定义的查找/替换或使用所有参数搜索/替换,请参阅查找和转换(我写的)。特别是有很多用于设置files to include范围过滤器的选项 - 例如当前文件或在先前搜索结果中找到的最后一个文件,以将搜索范围缩小到仅这些文件。
还有一种内置方法可以跨文件查找,我不知道您的问题后是否添加了参数。无论如何,我同意有时很难发现哪些命令可以接受参数。
有时,命令中的键绑定内的智能感知会显示它们,但并非总是如此。
所以检查一下:
{
"key": "ctrl+shift+f",
"command": "workbench.action.findInFiles",
"args": {
<cursor here> // cursor there and type Ctrl+space
}
}
Run Code Online (Sandbox Code Playgroud)
将显示可用的内容,args如下例所示。
{
"key": "ctrl+shift+f",
"command": "workbench.action.findInFiles",
"args": {
"query": "Company(\\w+)", // needs to be double-escaped
"replace": "User$1",
"triggerSearch": true,
"isRegex": true,
// "filesToExclude": "",
// "filesToInclude": "",
"matchWholeWord": true,
"isCaseSensitive": true
}
},
Run Code Online (Sandbox Code Playgroud)
这将执行搜索,但不会在您的文件中进行实际替换 - 您必须replace [all]自己触发。
安装扩展替换规则。
在您的(工作空间或用户)中构建搜索替换settings.json。阅读有关可能性的页面。
"replacerules.rules": {
"Replace User": {
"find": "User(\d+)",
"replace": "Player$1"
}
}
Run Code Online (Sandbox Code Playgroud)
定义keybindings.json以下键绑定:
{
"key": "ctrl+shift+alt+u",
"command": "replacerules.runRule",
"when": "editorTextFocus",
"args": { "ruleName": "Replace User"}
}
Run Code Online (Sandbox Code Playgroud)
如果您选择某些文本,则搜索替换将仅在选择范围内执行。
| 归档时间: |
|
| 查看次数: |
2146 次 |
| 最近记录: |