我可以在 vscode 中定义替换操作的任务吗? [英] Can I define a task for Replace Operation in vscode?

查看:31
本文介绍了我可以在 vscode 中定义替换操作的任务吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我每天都会在我的解决方案中用"替换每个 debugger; 短语.我认为如果有办法为此操作定义任务可能会很好.你知道解决办法吗.有这个功能吗?

解决方案

您将需要一个宏扩展,例如 .gif 软件在击键上很不稳定 - 它只是 Ctrl-Alt-U.

I replace every debugger; phrase with "" in my solution some times a day. I thought it could be well if there is a way to define a task for this operation. Do you know the solution. is there this feature?

解决方案

You will need a macro extension such as multi-command. It will allow you to chain commands together to run with one keybinding.

In your settings.json:

{
  "command": "multiCommand.removeDebugger",
  // "interval": 250,
  "sequence": [

    "workbench.action.findInFiles",
    // "toggleSearchRegex",  // depending if the default is regex on or off
                             // and where you want it to end up

    "search.action.refreshSearchResults",
    "workbench.action.replaceInFiles",
    "search.focus.nextInputBox",
    "editor.action.clipboardCutAction",

    "search.action.replaceAll"
  ]
},

This will open the "Find In Files" panel. Then it will run the command to actually search for your chosen string across files (which is a necessary step before doing a replace). Then it will move to the "replace input box", clear its contents (since you want to replace "debugger;" with nothing) and run the replace in all files command. VSCode will prompt you if you really want to do it.

In your keybindings.json put some keybinding of your choice, such as:

{
  "key": "ctrl+alt+u",
  "command": "extension.multiCommand.execute",
  "args": { "command": "multiCommand.removeDebugger" }
},

The only requirement is that you highlight the phrase you want to search for first - in your case debugger;- and then trigger it with Ctrl-Alt-U or whatever.

Here is a demo gif of it working - I slowed it way down so it could seen going through the steps:

. The gif software is wonky on the keystrokes - it is just Ctrl-Alt-U.

这篇关于我可以在 vscode 中定义替换操作的任务吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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