“我们可以sendSequence 到终端以显示上一个命令/下一个命令(就像我们单击向上/向下箭头时一样)”
{
"key": "alt+x", // or whatever you choose
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "\u001b[A\n"
}
// 1 up arrow or previous command, works in cmd, git bash and powershell
// the \n at the end makes it execute the previous command immediately,
// leave it off if you don't want to do that
// \u000d, a carriage return, is equivalent to \n if you prefer to use that, so
// \u001b[A\u000d does the same thing as \u001b[A\n
> /** Carriage Return (Caret = ^M, C = \r) */
> export const CR = '\x0d';
{
"key": "alt+y", // or whatever you choose
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "\u001b[B\n"
}
// 1 down arrow
// see comment above about immediate command execution
有关这些箭头命令,请参阅https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
使用 CSI 的函数,按最终字符排序
CSI Ps A光标向上 Ps 次(默认 = 1)(CUU)。
CSI Ps B 光标向下 Ps 时间(默认 = 1)(CUD)。
这部分\u001b[是文档中提到的转义序列或CSI。紧随其后的是A 向上箭头(向上箭头)所以\u001b[A 或跟随转义序列B 向下箭头,所以\u001b[B。
[理论上,您应该可以同时使用 2 个(上面提到的Ps 部分)向上箭头,但这似乎在 vscode 中对我在 vscode 中不起作用。]
{
"key": "ctrl+e",
"command": "workbench.action.terminal.sendSequence",
"args": { "text": "\u0005" }, // move cursor to end of line, bash at least
"when": "terminalFocus"
},
{
"key": "ctrl+a",
"command": "workbench.action.terminal.sendSequence",
"args": { "text": "\u0001" }, // move cursor to start of line, bash at least
"when": "terminalFocus"
},
我使用通常的键绑定 - 至少在 bash 中 - 用于转到命令行的开头或结尾。参见,例如,http://teohm.com/blog/shortcuts-to-move-faster-in-bash-command-line/
来自这个文档https://github.com/xtermjs/xterm.js/blob/0e45909c7e79c83452493d2cd46d99c0a0bb585f/src/common/data/EscapeSequences.ts
我们看到 Ctrl+A 是:
/** 标题开始(插入符号 = ^A)*/ [即 Ctrl+A]
导出常量 SOH = '\x01';
所以我使用\u0001 unicode 序列来替换列出的\x01,它不适用于sendSequence 命令。
同样,发送 Ctrl+E 到终端以转到命令行末尾,我们看到 Ctrl +E 是:
/** 查询 (Caret = ^E) */ [即 Ctrl+E]
导出常量 ENQ = '\x05';
或 unicode \u0005.
现在,您的终端 shell 可能会使用 Ctrl+A 和 Ctrl+E 以外的其他内容来执行 go开始/结束命令行。如果我的键绑定对您不起作用,请找出您的 shell 用于 go to start/end 的内容,看看它们是否在 https://github.com/xtermjs/xterm.js/blob/0e45909c7e79c83452493d2cd46d99c0a0bb585f/src/common/data/EscapeSequences.ts 中