需要 VSCode sendSequence 键绑定用于上一个命令、下一个命令、移动到行首、移动到行尾终端命令 [英] Need VSCode sendSequence keybindings for previous command, next command, move to start of line, move to end of line terminal commands
问题描述
我当前的自定义键绑定
<代码> {"key": "alt+b","command": "workbench.action.terminal.sendSequence","when": "终端焦点",参数":{文本":\u0017"}},{"key": "alt+j","command": "workbench.action.terminal.sendSequence","args": { "text": "\u001bb" }},{"key": "alt+l","command": "workbench.action.terminal.sendSequence","args": { "text": "\u001bf" }},{"key": "alt+n","command": "workbench.action.terminal.sendSequence","when": "终端焦点",参数":{文本":\u001bd"}
这些适用于 1.45 更新(集成终端更新)
参考 - 但我需要更多信息
我想使用 'ijkl' 键,例如 'wasd' 游戏标准,就像我的自定义项目 直觉
所以我的想法是
我们可以向终端发送序列以显示上一个命令/下一个命令(就像我们点击向上/向下箭头)
moveToLineStart/moveToLineEnd 序列被此更新删除(抱歉我找不到或无法制作序列)我们可以通过
sendSequence
获得这个效果吗?
我们能否sendSequence
到终端显示上一个命令/下一个命令(就像我们点击向上/向下箭头)">
<代码> {"key": "alt+x",//或任何你选择的"command": "workbench.action.terminal.sendSequence",参数":{文本":\u001b[A\n"}//1 个向上箭头或上一个命令,适用于 cmd、git bash 和 powershell//末尾的 \n 使它立即执行上一个命令,//如果您不想这样做,请关闭它//\u000d,一个回车,等价于\n,如果你喜欢使用它,所以//\u001b[A\u000d 和 \u001b[A\n 做同样的事情>/** 回车符 (Caret = ^M, C = \r) */>导出 const CR = '\x0d';{"key": "alt+y",//或任何你选择的"command": "workbench.action.terminal.sendSequence",参数":{文本":\u001b[B\n"}//1 向下箭头//请参阅上面关于立即执行命令的评论
有关这些箭头命令,请参阅 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
部分)向上箭头执行 \u001b[2A
,但这似乎永远不起作用在 vscode 中为我在 vscode 中.]
<代码>{"key": "ctrl+e","command": "workbench.action.terminal.sendSequence","args": { "text": "\u0005" },//将光标移动到行尾,至少 bash"when": "终端焦点"},{"key": "ctrl+a","command": "workbench.action.terminal.sendSequence","args": { "text": "\u0001" },//将光标移动到行首,至少 bash"when": "终端焦点"},
我使用常用的键绑定 - 至少在 bash 中 - 用于转到命令行的开头或结尾.参见,例如,http://teohm.com/blog/shortcuts-to-move-faster-in-bash-command-line/
我们看到 Ctrl+A 是:
<块引用>/** 标题开始(插入符号 = ^A)*/[即 Ctrl+A]export const SOH = '\x01';
所以我使用 \u0001
unicode 序列来替换列出的 \x01
,它不适用于 sendSequence
命令.>
同样,发送 Ctrl+E 到终端以转到命令行的末尾,我们看到 Ctrl+E 是:
<块引用>/** 查询 (Caret = ^E) */[即 Ctrl+E]export const ENQ = '\x05';
或unicode \u0005
.
现在,你的终端 shell 可能会使用 Ctrl+A 和 Ctrl+E 以外的其他东西开始/结束命令行.如果我的键绑定对您不起作用,请找出您的 shell 用于开始/结束并查看它们是否在 https://github.com/xtermjs/xterm.js/blob/0e45909c7e79c83452493d2cd46d99c0a0bb585f/src/common/data/EscapeSequences./p>My current custom keybindings
{
"key": "alt+b",
"command": "workbench.action.terminal.sendSequence",
"when": "terminalFocus",
"args": {
"text": "\u0017"
}
},
{
"key": "alt+j",
"command": "workbench.action.terminal.sendSequence",
"args": { "text": "\u001bb" }
},
{
"key": "alt+l",
"command": "workbench.action.terminal.sendSequence",
"args": { "text": "\u001bf" }
},
{
"key": "alt+n",
"command": "workbench.action.terminal.sendSequence",
"when": "terminalFocus",
"args": {
"text": "\u001bd"
}
These work well with 1.45 update (integrated terminal update)
Reference - but I need more Information
I want to use 'ijkl' keys like 'wasd' gaming standard like my custom project intuiter
So My Idea is
Can we send sequence to terminal to show Previous Command/Next command (like when we click Up/Down Arrow)
moveToLineStart/moveToLineEnd sequence is removed with this update(sorry I can't find or make sequence) can we get this effect by
sendSequence
?
"Can we sendSequence
to terminal to show Previous Command/Next Command (like when we click Up/Down Arrow)"
{
"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
For these arrow commands, see https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
Functions using CSI , ordered by the final character(s)
CSI Ps A Cursor Up Ps Times (default = 1) (CUU).
CSI Ps B Cursor Down Ps Times (default = 1) (CUD).
This part \u001b[
is the escape sequence or CSI
referred to in the document. Follow that with an A
for cursur up (up arrow) so \u001b[A
or follow the escape sequence with a B
for a down arrow, so \u001b[B
.
[Theoretically, you should be able to do \u001b[2A
for 2 (the Ps
part referred to above) up arrows at once but that never seems to work in vscode for me in 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"
},
I used the usual keybindings - at least in bash - for go to the start or end of the command line. See, e.g., http://teohm.com/blog/shortcuts-to-move-faster-in-bash-command-line/
From this document https://github.com/xtermjs/xterm.js/blob/0e45909c7e79c83452493d2cd46d99c0a0bb585f/src/common/data/EscapeSequences.ts
we see that Ctrl+A is :
/** Start of Heading (Caret = ^A) */ [that's Ctrl+A] export const SOH = '\x01';
so I used \u0001
the unicode sequence to replace that listed \x01
which won't work with the sendSequence
command.
Likewise, to send a Ctrl+E to the terminal for the go to the end of the command line, we see that Ctrl+E is :
/** Enquiry (Caret = ^E) */ [that's Ctrl+E] export const ENQ = '\x05';
or unicode \u0005
.
Now, your terminal shell might use something other than Ctrl+A and Ctrl+E for go to start/end of the command line. If my keybindings don't work for you, find out what your shell uses for go to start/end and see if they are in https://github.com/xtermjs/xterm.js/blob/0e45909c7e79c83452493d2cd46d99c0a0bb585f/src/common/data/EscapeSequences.ts
这篇关于需要 VSCode sendSequence 键绑定用于上一个命令、下一个命令、移动到行首、移动到行尾终端命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!