使用键绑定在VSCode中执行预定义的Find-Replace-All [英] Perform pre-defined Find-Replace-All in VSCode using a keybinding

查看:88
本文介绍了使用键绑定在VSCode中执行预定义的Find-Replace-All的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎找不到一个可以从VSCode键绑定运行的文档化命令的完整列表.

I can't seem to find a good list of documented commands that can be run from VSCode keybindings.

在在线VSCode文档上,命令指南列出了两种方法发现命令:

On the online VSCode documentation, the Commands Guide lists two ways to discover commands:

找到的用于键盘快捷键的命令通常是不带参数的简单"命令.高级命令api"似乎缺少一些非常基本的基本命令.

The commands found for keyboard shortcuts are usually "simple" commands that do not take arguments. The "advanced commands api" seems to be missing some very basic, fundamental commands.

例如,在 VSCode键绑定页面上,有一个具有以下示例条目的命令参数"部分:

For example, on the VSCode Keybindings page there is a section called "Command Arguments" that has the following example entry:

{ "key": "enter", "command": "type",
  "args": { "text": "Hello World" },
  "when": "editorTextFocus" }

但是我没有看到记录 type 命令的任何地方.因此,我认为可能还存在其他类似的基本命令,但是我不知道在哪里可以找到它们的文档.

But I don't see anywhere that the type command is documented. So I assume there are probably several other basic commands like this that exist but I don't know where to find documentation for them.

无论如何,此刻我真正要寻找的是一个命令,我可以运行该命令在当前编辑器中进行预定义的搜索和替换,指定查找文本,替换文本和选项...类似下方:

Anyway, what I am really looking for at the moment is a command that I can run to do a pre-defined search and replace in the current editor, specifying the find text, replacement text, and options... something like below:

{ "key": "ctrl+shift+8", 
  "command": "findReplaceAll",
  "args": { 
    "findText": "Company(\\w+)", 
    "replaceText": "User$1"
    "options": { "ignoreCase": false, "wholeWord": true, "regex": true }
  },
  "when": "editorTextFocus" }

但是我无法在文档中找到任何这样的 findReplaceAll 命令或类似的命令,但是肯定有类似的东西存在,对吧?

But I haven't been able to find any such findReplaceAll command or anything similar in the documentation, but certainly something like this must exist, right?

谢谢!

推荐答案

有一种内置方法可以执行此操作,我不知道是否在您的问题后添加了参数.无论如何,我都同意有时很难发现哪些命令可以接受参数.

There is a built-in way to do this, I don't know if arguments were added after your question or not. In any case, I agree that it is sometimes difficult to discover which commands can take arguments.

有时候,您命令中的键绑定中的智能感知将使它们浮出水面,但并非总是如此.

Sometimes, intellisense within the keybindings in your command will surface them but not always.

所以检查一下:

{
 "key": "ctrl+shift+f",
 "command": "workbench.action.findInFiles",
 "args": {
   <cursor here>  // cursor there and type Ctrl+space
  }
}

将显示可用的 args ,如以下示例所示.

will show those the available args as in the below example.

{
  "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
  }
},

这将执行搜索,但不会在文件中进行实际替换-您必须自己触发替换[all] .

This will perform the search but not do the actual replacement in your files - you will have to trigger replace [all] yourself.

这篇关于使用键绑定在VSCode中执行预定义的Find-Replace-All的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆