vscode终端:无需提示即可终止进程 [英] vscode terminal: terminate process without prompt

查看:1413
本文介绍了vscode终端:无需提示即可终止进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我习惯于通过两次按 Ctrl + C 来终止CLI中的进程,但这在vscode的集成终端中不起作用。它提示您进行确认。有没有办法以相同的方式使用它?甚至更好,只需按下1次键即可。

I'm used to terminating a process in the CLI by pressing Ctrl+C twice but that doesn't work in vscode's integrated terminal. It prompts for confirmation. Is there a way to use it the same way? Or even better, with 1 keypress.

推荐答案

不带扩展名:



workbench.action.terminal.sendSequence 添加到settings.json中的 terminal.integrated.commandsToSkipShell 列表中通过转到文件→首选项→设置,然后搜索字符串 terminal.integrated.commandsToSkipShell ,然后单击在settings.json中编辑。

Without extensions:

add "workbench.action.terminal.sendSequence" to the terminal.integrated.commandsToSkipShell list in your settings.json by going to File → Preferences → Settings, then searching for the string terminal.integrated.commandsToSkipShell, and then clicking "edit in settings.json".

如果settings.json中没有 terminal.integrated.commandsToSkipShell 条目,只需将其添加:

If there is no "terminal.integrated.commandsToSkipShell" entry in your settings.json, simply add it:

... ,
"terminal.integrated.commandsToSkipShell": [
  "workbench.action.terminal.sendSequence"
]

然后,您还需要添加以下键绑定(文件→首选项→键盘快捷键→打开keybindings.json):

Then you will also need to add the following key binding (File → Preferences → Keyboard Shortcuts → open keybindings.json):

{
    "key": "ctrl+c",
    "command": "workbench.action.terminal.sendSequence",
    "args": {
        "text": "\u0003Y\u000D"
    },
    "when": "terminalFocus && !terminalTextSelected"
}

请注意,此解决方案要求您使用 Ctrl - C 两次,并且只能在Visual Studio Code终端中使用。

Note that this solution requires you to use Ctrl-C twice, and only works in the Visual Studio Code terminal.

这也将更改您在终端上运行的依赖于两个 ctrl - c 指令的任何工具的行为:现在您发送的大写字母 Y 和换行符作为第二条指令,请确保您正在运行的任何内容都具有退出退出的替代方法。

This will also change the behaviour for any tool you run in the terminal that relies on two ctrl-c instructions: as you are now sending the capital letter Y and a newline as second instruction instead, make sure whatever you're running has an alternate means of exiting available.

您可以使用多命令扩展,通过添加以下设置:

You can use the multi-command extension, by adding this setting:

"multiCommand.commands": [
  {
    "command": "multiCommand.terminateTerminal",
    "interval": 1000,
    "sequence": [
      {
        "command": "workbench.action.terminal.sendSequence",
        "args": {
          "text": "\u0003"
        }
      },
      {
        "command": "workbench.action.terminal.sendSequence",
        "args": {
          "text": "Y\u000D"
        }
      },
    ]
  }

c $ c> interval 在两个 sendSequence 命令之间提供了一个暂停,并且两个命令都是必需的:

The interval provides a pause between the two sendSequence commands, and both commands are required:


  • u\003 是文本的结尾(Caret = ^ C)。

  • u\003 is an End of Text (Caret = ^C).

u\000D Return

然后在keybindings.json中添加键绑定:

Then add a keybinding in keybindings.json:

{
  "key": "ctrl+shift+c",
  "command": "extension.multiCommand.execute",
  "args": { "command": "multiCommand.terminateTerminal" },
},

某些键组合将不会工作(l (两次按 Ctrl - C 的标准顺序),但使用 Ctrl - Shift - C ,无论光标焦点位于编辑器,文件资源管理器还是运行良好的终端中。

Certain key combinations will not work (like the standard sequence of Ctrl-C twice), but with Ctrl-Shift-C, whether the cursor focus is in an editor, the file explorer, or the terminal it works well.

请注意,这不会杀死或关闭终端或影响其历史,它只会停止当前的工作。

Note that this does not kill or close the terminal or affect its history, it just stops the current job there.

这篇关于vscode终端:无需提示即可终止进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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