vscode终端:在没有提示的情况下终止进程 [英] vscode terminal: terminate process without prompt

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

问题描述

我习惯于在 CLI 中通过按 Ctrl+C 两次来终止进程,但这在 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": "u0003Yu000D"
    },
    "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": "Yu000D"
        }
      },
    ]
  }

interval 提供了两个 sendSequence 命令之间的暂停,并且这两个命令都是必需的:

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

  • u03 是文本的结尾(插入符号 = ^C).

  • u03 is an End of Text (Caret = ^C).

u00D 是一个 返回.

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

Then add a keybinding in keybindings.json:

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

某些组合键将不起作用(就像 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天全站免登陆